diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/asset-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/asset-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 38cbcbd76681..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const asset = require('@google-cloud/asset'); - -function main() { - const assetServiceClient = new asset.AssetServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index aa2ac18d2d15..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as asset from '@google-cloud/asset'; - -function main() { - const assetServiceClient = new asset.AssetServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 40aa52c8666e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {AssetServiceClient} from '@google-cloud/asset'; - -// check that the client class type name can be used -function doStuffWithAssetServiceClient(client: AssetServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const assetServiceClient = new AssetServiceClient(); - doStuffWithAssetServiceClient(assetServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/test/gapic_asset_service_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/test/gapic_asset_service_v1.ts.baseline deleted file mode 100644 index 685a59b84d45..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/esm/test/gapic_asset_service_v1.ts.baseline +++ /dev/null @@ -1,1162 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as assetserviceModule from '../src/index.js'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v1.AssetServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new assetserviceModule.v1.AssetServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudasset.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new assetserviceModule.v1.AssetServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = assetserviceModule.v1.AssetServiceClient.servicePath; - assert.strictEqual(servicePath, 'cloudasset.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = assetserviceModule.v1.AssetServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudasset.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new assetserviceModule.v1.AssetServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudasset.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new assetserviceModule.v1.AssetServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudasset.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new assetserviceModule.v1.AssetServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudasset.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new assetserviceModule.v1.AssetServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudasset.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new assetserviceModule.v1.AssetServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = assetserviceModule.v1.AssetServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new assetserviceModule.v1.AssetServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.assetServiceStub, undefined); - await client.initialize(); - assert(client.assetServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.assetServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.assetServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new assetserviceModule.v1.AssetServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new assetserviceModule.v1.AssetServiceClient({ - 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); - }); - }); - - describe('batchGetAssetsHistory', () => { - it('invokes batchGetAssetsHistory without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryResponse() - ); - client.innerApiCalls.batchGetAssetsHistory = stubSimpleCall(expectedResponse); - const [response] = await client.batchGetAssetsHistory(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetAssetsHistory without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryResponse() - ); - client.innerApiCalls.batchGetAssetsHistory = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchGetAssetsHistory( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IBatchGetAssetsHistoryResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetAssetsHistory with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchGetAssetsHistory = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.batchGetAssetsHistory(request), expectedError); - const actualRequest = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetAssetsHistory with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.batchGetAssetsHistory(request), expectedError); - }); - }); - - describe('createFeed', () => { - it('invokes createFeed without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.CreateFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.createFeed = stubSimpleCall(expectedResponse); - const [response] = await client.createFeed(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createFeed without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.CreateFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.createFeed = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createFeed( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IFeed|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createFeed with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.CreateFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createFeed = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createFeed(request), expectedError); - const actualRequest = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createFeed with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.CreateFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createFeed(request), expectedError); - }); - }); - - describe('getFeed', () => { - it('invokes getFeed without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.GetFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.getFeed = stubSimpleCall(expectedResponse); - const [response] = await client.getFeed(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getFeed without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.GetFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.getFeed = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getFeed( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IFeed|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getFeed with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.GetFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getFeed = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getFeed(request), expectedError); - const actualRequest = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getFeed with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.GetFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getFeed(request), expectedError); - }); - }); - - describe('listFeeds', () => { - it('invokes listFeeds without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsResponse() - ); - client.innerApiCalls.listFeeds = stubSimpleCall(expectedResponse); - const [response] = await client.listFeeds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFeeds without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsResponse() - ); - client.innerApiCalls.listFeeds = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listFeeds( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IListFeedsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFeeds with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listFeeds = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listFeeds(request), expectedError); - const actualRequest = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFeeds with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listFeeds(request), expectedError); - }); - }); - - describe('updateFeed', () => { - it('invokes updateFeed without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.UpdateFeedRequest() - ); - request.feed ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']); - request.feed.name = defaultValue1; - const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.updateFeed = stubSimpleCall(expectedResponse); - const [response] = await client.updateFeed(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateFeed without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.UpdateFeedRequest() - ); - request.feed ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']); - request.feed.name = defaultValue1; - const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.updateFeed = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateFeed( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IFeed|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateFeed with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.UpdateFeedRequest() - ); - request.feed ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']); - request.feed.name = defaultValue1; - const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateFeed = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateFeed(request), expectedError); - const actualRequest = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateFeed with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.UpdateFeedRequest() - ); - request.feed ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']); - request.feed.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateFeed(request), expectedError); - }); - }); - - describe('deleteFeed', () => { - it('invokes deleteFeed without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.DeleteFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteFeed = stubSimpleCall(expectedResponse); - const [response] = await client.deleteFeed(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteFeed without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.DeleteFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteFeed = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteFeed( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteFeed with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.DeleteFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteFeed = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteFeed(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteFeed with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.DeleteFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteFeed(request), expectedError); - }); - }); - - describe('exportAssets', () => { - it('invokes exportAssets without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ExportAssetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportAssets = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportAssets(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAssets without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ExportAssetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportAssets = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportAssets( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAssets with call error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ExportAssetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportAssets = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportAssets(request), expectedError); - const actualRequest = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAssets with LRO error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ExportAssetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportAssets = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportAssets(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportAssetsProgress without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportAssetsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportAssetsProgress with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportAssetsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('folderFeed', () => { - const fakePath = "/rendered/path/folderFeed"; - const expectedParameters = { - folder: "folderValue", - feed: "feedValue", - }; - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderFeedPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderFeedPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderFeedPath', () => { - const result = client.folderFeedPath("folderValue", "feedValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderFeedPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderFeedName', () => { - const result = client.matchFolderFromFolderFeedName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchFeedFromFolderFeedName', () => { - const result = client.matchFeedFromFolderFeedName(fakePath); - assert.strictEqual(result, "feedValue"); - assert((client.pathTemplates.folderFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationFeed', () => { - const fakePath = "/rendered/path/organizationFeed"; - const expectedParameters = { - organization: "organizationValue", - feed: "feedValue", - }; - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationFeedPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationFeedPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationFeedPath', () => { - const result = client.organizationFeedPath("organizationValue", "feedValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationFeedPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationFeedName', () => { - const result = client.matchOrganizationFromOrganizationFeedName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchFeedFromOrganizationFeedName', () => { - const result = client.matchFeedFromOrganizationFeedName(fakePath); - assert.strictEqual(result, "feedValue"); - assert((client.pathTemplates.organizationFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectFeed', () => { - const fakePath = "/rendered/path/projectFeed"; - const expectedParameters = { - project: "projectValue", - feed: "feedValue", - }; - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectFeedPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectFeedPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectFeedPath', () => { - const result = client.projectFeedPath("projectValue", "feedValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectFeedPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectFeedName', () => { - const result = client.matchProjectFromProjectFeedName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchFeedFromProjectFeedName', () => { - const result = client.matchFeedFromProjectFeedName(fakePath); - assert.strictEqual(result, "feedValue"); - assert((client.pathTemplates.projectFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/package.json b/core/generator/gapic-generator-typescript/baselines/asset-esm/package.json index 659bdec70889..5760541b4ea4 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/asset-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/asset-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/asset-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/asset-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/asset-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/asset/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/asset/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/asset/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/asset/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/asset/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/asset/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/asset/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/asset/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/asset/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/asset/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/asset/package.json b/core/generator/gapic-generator-typescript/baselines/asset/package.json index ee6499cbe0c7..33d5615e4ba7 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset/package.json +++ b/core/generator/gapic-generator-typescript/baselines/asset/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/asset/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/asset/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index a483c1902590..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const asset = require('@google-cloud/asset'); - -function main() { - const assetServiceClient = new asset.AssetServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/asset/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/asset/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 9e97334ff46b..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {AssetServiceClient} from '@google-cloud/asset'; - -// check that the client class type name can be used -function doStuffWithAssetServiceClient(client: AssetServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const assetServiceClient = new AssetServiceClient(); - doStuffWithAssetServiceClient(assetServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/asset/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/asset/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/asset/test/gapic_asset_service_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/asset/test/gapic_asset_service_v1.ts.baseline deleted file mode 100644 index 3116b196c337..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/asset/test/gapic_asset_service_v1.ts.baseline +++ /dev/null @@ -1,1153 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as assetserviceModule from '../src'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v1.AssetServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new assetserviceModule.v1.AssetServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudasset.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new assetserviceModule.v1.AssetServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = assetserviceModule.v1.AssetServiceClient.servicePath; - assert.strictEqual(servicePath, 'cloudasset.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = assetserviceModule.v1.AssetServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudasset.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new assetserviceModule.v1.AssetServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudasset.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new assetserviceModule.v1.AssetServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudasset.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new assetserviceModule.v1.AssetServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudasset.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new assetserviceModule.v1.AssetServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudasset.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new assetserviceModule.v1.AssetServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = assetserviceModule.v1.AssetServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new assetserviceModule.v1.AssetServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.assetServiceStub, undefined); - await client.initialize(); - assert(client.assetServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.assetServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.assetServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new assetserviceModule.v1.AssetServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new assetserviceModule.v1.AssetServiceClient({ - 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); - }); - }); - - describe('batchGetAssetsHistory', () => { - it('invokes batchGetAssetsHistory without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryResponse() - ); - client.innerApiCalls.batchGetAssetsHistory = stubSimpleCall(expectedResponse); - const [response] = await client.batchGetAssetsHistory(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetAssetsHistory without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryResponse() - ); - client.innerApiCalls.batchGetAssetsHistory = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchGetAssetsHistory( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IBatchGetAssetsHistoryResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetAssetsHistory with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchGetAssetsHistory = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.batchGetAssetsHistory(request), expectedError); - const actualRequest = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchGetAssetsHistory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchGetAssetsHistory with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.BatchGetAssetsHistoryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.BatchGetAssetsHistoryRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.batchGetAssetsHistory(request), expectedError); - }); - }); - - describe('createFeed', () => { - it('invokes createFeed without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.CreateFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.createFeed = stubSimpleCall(expectedResponse); - const [response] = await client.createFeed(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createFeed without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.CreateFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.createFeed = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createFeed( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IFeed|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createFeed with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.CreateFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createFeed = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createFeed(request), expectedError); - const actualRequest = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createFeed with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.CreateFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.CreateFeedRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createFeed(request), expectedError); - }); - }); - - describe('getFeed', () => { - it('invokes getFeed without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.GetFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.getFeed = stubSimpleCall(expectedResponse); - const [response] = await client.getFeed(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getFeed without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.GetFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.getFeed = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getFeed( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IFeed|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getFeed with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.GetFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getFeed = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getFeed(request), expectedError); - const actualRequest = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getFeed with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.GetFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.GetFeedRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getFeed(request), expectedError); - }); - }); - - describe('listFeeds', () => { - it('invokes listFeeds without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsResponse() - ); - client.innerApiCalls.listFeeds = stubSimpleCall(expectedResponse); - const [response] = await client.listFeeds(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFeeds without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsResponse() - ); - client.innerApiCalls.listFeeds = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listFeeds( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IListFeedsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFeeds with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listFeeds = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listFeeds(request), expectedError); - const actualRequest = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listFeeds as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listFeeds with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ListFeedsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ListFeedsRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listFeeds(request), expectedError); - }); - }); - - describe('updateFeed', () => { - it('invokes updateFeed without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.UpdateFeedRequest() - ); - request.feed ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']); - request.feed.name = defaultValue1; - const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.updateFeed = stubSimpleCall(expectedResponse); - const [response] = await client.updateFeed(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateFeed without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.UpdateFeedRequest() - ); - request.feed ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']); - request.feed.name = defaultValue1; - const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.asset.v1.Feed() - ); - client.innerApiCalls.updateFeed = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateFeed( - request, - (err?: Error|null, result?: protos.google.cloud.asset.v1.IFeed|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateFeed with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.UpdateFeedRequest() - ); - request.feed ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']); - request.feed.name = defaultValue1; - const expectedHeaderRequestParams = `feed.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateFeed = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateFeed(request), expectedError); - const actualRequest = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateFeed with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.UpdateFeedRequest() - ); - request.feed ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.UpdateFeedRequest', ['feed', 'name']); - request.feed.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateFeed(request), expectedError); - }); - }); - - describe('deleteFeed', () => { - it('invokes deleteFeed without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.DeleteFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteFeed = stubSimpleCall(expectedResponse); - const [response] = await client.deleteFeed(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteFeed without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.DeleteFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteFeed = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteFeed( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteFeed with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.DeleteFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteFeed = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteFeed(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteFeed as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteFeed with closed client', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.DeleteFeedRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.DeleteFeedRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteFeed(request), expectedError); - }); - }); - - describe('exportAssets', () => { - it('invokes exportAssets without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ExportAssetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportAssets = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportAssets(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAssets without error using callback', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ExportAssetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportAssets = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportAssets( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAssets with call error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ExportAssetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportAssets = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportAssets(request), expectedError); - const actualRequest = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAssets with LRO error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.asset.v1.ExportAssetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.asset.v1.ExportAssetsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportAssets = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportAssets(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAssets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportAssetsProgress without error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportAssetsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportAssetsProgress with error', async () => { - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportAssetsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('folderFeed', async () => { - const fakePath = "/rendered/path/folderFeed"; - const expectedParameters = { - folder: "folderValue", - feed: "feedValue", - }; - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderFeedPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderFeedPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderFeedPath', () => { - const result = client.folderFeedPath("folderValue", "feedValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderFeedPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderFeedName', () => { - const result = client.matchFolderFromFolderFeedName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchFeedFromFolderFeedName', () => { - const result = client.matchFeedFromFolderFeedName(fakePath); - assert.strictEqual(result, "feedValue"); - assert((client.pathTemplates.folderFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationFeed', async () => { - const fakePath = "/rendered/path/organizationFeed"; - const expectedParameters = { - organization: "organizationValue", - feed: "feedValue", - }; - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationFeedPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationFeedPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationFeedPath', () => { - const result = client.organizationFeedPath("organizationValue", "feedValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationFeedPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationFeedName', () => { - const result = client.matchOrganizationFromOrganizationFeedName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchFeedFromOrganizationFeedName', () => { - const result = client.matchFeedFromOrganizationFeedName(fakePath); - assert.strictEqual(result, "feedValue"); - assert((client.pathTemplates.organizationFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectFeed', async () => { - const fakePath = "/rendered/path/projectFeed"; - const expectedParameters = { - project: "projectValue", - feed: "feedValue", - }; - const client = new assetserviceModule.v1.AssetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectFeedPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectFeedPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectFeedPath', () => { - const result = client.projectFeedPath("projectValue", "feedValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectFeedPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectFeedName', () => { - const result = client.matchProjectFromProjectFeedName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchFeedFromProjectFeedName', () => { - const result = client.matchFeedFromProjectFeedName(fakePath); - assert.strictEqual(result, "feedValue"); - assert((client.pathTemplates.projectFeedPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/asset/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/asset/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/asset/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/asset/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 50617ba5a820..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const storage = require('storage'); - -function main() { - const bigQueryStorageClient = new storage.BigQueryStorageClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index cf238c1a734f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as storage from 'storage'; - -function main() { - const bigQueryStorageClient = new storage.BigQueryStorageClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 3e74dfdae58d..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {BigQueryStorageClient} from 'storage'; - -// check that the client class type name can be used -function doStuffWithBigQueryStorageClient(client: BigQueryStorageClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const bigQueryStorageClient = new BigQueryStorageClient(); - doStuffWithBigQueryStorageClient(bigQueryStorageClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/test/gapic_big_query_storage_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/test/gapic_big_query_storage_v1beta1.ts.baseline deleted file mode 100644 index 3a822fcad5ad..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/esm/test/gapic_big_query_storage_v1beta1.ts.baseline +++ /dev/null @@ -1,943 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as bigquerystorageModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -describe('v1beta1.BigQueryStorageClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquerystorage.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = bigquerystorageModule.v1beta1.BigQueryStorageClient.servicePath; - assert.strictEqual(servicePath, 'bigquerystorage.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = bigquerystorageModule.v1beta1.BigQueryStorageClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquerystorage.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquerystorage.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquerystorage.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquerystorage.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquerystorage.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new bigquerystorageModule.v1beta1.BigQueryStorageClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = bigquerystorageModule.v1beta1.BigQueryStorageClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.bigQueryStorageStub, undefined); - await client.initialize(); - assert(client.bigQueryStorageStub); - }); - - it('has close method for the initialized client', done => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.bigQueryStorageStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.bigQueryStorageStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - 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); - }); - }); - - describe('createReadSession', () => { - it('invokes createReadSession without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest() - ); - request.tableReference ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'projectId']); - request.tableReference.projectId = defaultValue1; - request.tableReference ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'datasetId']); - request.tableReference.datasetId = defaultValue2; - const expectedHeaderRequestParams = `table_reference.project_id=${defaultValue1 ?? '' }&table_reference.dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadSession() - ); - client.innerApiCalls.createReadSession = stubSimpleCall(expectedResponse); - const [response] = await client.createReadSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createReadSession without error using callback', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest() - ); - request.tableReference ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'projectId']); - request.tableReference.projectId = defaultValue1; - request.tableReference ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'datasetId']); - request.tableReference.datasetId = defaultValue2; - const expectedHeaderRequestParams = `table_reference.project_id=${defaultValue1 ?? '' }&table_reference.dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadSession() - ); - client.innerApiCalls.createReadSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createReadSession( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.storage.v1beta1.IReadSession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createReadSession with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest() - ); - request.tableReference ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'projectId']); - request.tableReference.projectId = defaultValue1; - request.tableReference ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'datasetId']); - request.tableReference.datasetId = defaultValue2; - const expectedHeaderRequestParams = `table_reference.project_id=${defaultValue1 ?? '' }&table_reference.dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createReadSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createReadSession(request), expectedError); - const actualRequest = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createReadSession with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest() - ); - request.tableReference ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'projectId']); - request.tableReference.projectId = defaultValue1; - request.tableReference ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'datasetId']); - request.tableReference.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createReadSession(request), expectedError); - }); - }); - - describe('batchCreateReadSessionStreams', () => { - it('invokes batchCreateReadSessionStreams without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest() - ); - request.session ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest', ['session', 'name']); - request.session.name = defaultValue1; - const expectedHeaderRequestParams = `session.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsResponse() - ); - client.innerApiCalls.batchCreateReadSessionStreams = stubSimpleCall(expectedResponse); - const [response] = await client.batchCreateReadSessionStreams(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchCreateReadSessionStreams without error using callback', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest() - ); - request.session ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest', ['session', 'name']); - request.session.name = defaultValue1; - const expectedHeaderRequestParams = `session.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsResponse() - ); - client.innerApiCalls.batchCreateReadSessionStreams = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchCreateReadSessionStreams( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchCreateReadSessionStreams with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest() - ); - request.session ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest', ['session', 'name']); - request.session.name = defaultValue1; - const expectedHeaderRequestParams = `session.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchCreateReadSessionStreams = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.batchCreateReadSessionStreams(request), expectedError); - const actualRequest = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchCreateReadSessionStreams with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest() - ); - request.session ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest', ['session', 'name']); - request.session.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.batchCreateReadSessionStreams(request), expectedError); - }); - }); - - describe('finalizeStream', () => { - it('invokes finalizeStream without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest() - ); - request.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest', ['stream', 'name']); - request.stream.name = defaultValue1; - const expectedHeaderRequestParams = `stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.finalizeStream = stubSimpleCall(expectedResponse); - const [response] = await client.finalizeStream(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes finalizeStream without error using callback', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest() - ); - request.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest', ['stream', 'name']); - request.stream.name = defaultValue1; - const expectedHeaderRequestParams = `stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.finalizeStream = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.finalizeStream( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes finalizeStream with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest() - ); - request.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest', ['stream', 'name']); - request.stream.name = defaultValue1; - const expectedHeaderRequestParams = `stream.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.finalizeStream = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.finalizeStream(request), expectedError); - const actualRequest = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes finalizeStream with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest() - ); - request.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest', ['stream', 'name']); - request.stream.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.finalizeStream(request), expectedError); - }); - }); - - describe('splitReadStream', () => { - it('invokes splitReadStream without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest() - ); - request.originalStream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest', ['originalStream', 'name']); - request.originalStream.name = defaultValue1; - const expectedHeaderRequestParams = `original_stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamResponse() - ); - client.innerApiCalls.splitReadStream = stubSimpleCall(expectedResponse); - const [response] = await client.splitReadStream(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes splitReadStream without error using callback', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest() - ); - request.originalStream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest', ['originalStream', 'name']); - request.originalStream.name = defaultValue1; - const expectedHeaderRequestParams = `original_stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamResponse() - ); - client.innerApiCalls.splitReadStream = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.splitReadStream( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes splitReadStream with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest() - ); - request.originalStream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest', ['originalStream', 'name']); - request.originalStream.name = defaultValue1; - const expectedHeaderRequestParams = `original_stream.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.splitReadStream = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.splitReadStream(request), expectedError); - const actualRequest = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes splitReadStream with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest() - ); - request.originalStream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest', ['originalStream', 'name']); - request.originalStream.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.splitReadStream(request), expectedError); - }); - }); - - describe('readRows', () => { - it('invokes readRows without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest() - ); - request.readPosition ??= {}; - request.readPosition.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']); - request.readPosition.stream.name = defaultValue1; - const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse() - ); - client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse); - const stream = client.readRows(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes readRows without error and gaxServerStreamingRetries enabled', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest() - ); - request.readPosition ??= {}; - request.readPosition.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']); - request.readPosition.stream.name = defaultValue1; - const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse() - ); - client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse); - const stream = client.readRows(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes readRows with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest() - ); - request.readPosition ??= {}; - request.readPosition.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']); - request.readPosition.stream.name = defaultValue1; - const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.readRows = stubServerStreamingCall(undefined, expectedError); - const stream = client.readRows(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes readRows with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest() - ); - request.readPosition ??= {}; - request.readPosition.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']); - request.readPosition.stream.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.readRows(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('Path templates', () => { - - describe('readSession', () => { - const fakePath = "/rendered/path/readSession"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - session: "sessionValue", - }; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.readSessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.readSessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('readSessionPath', () => { - const result = client.readSessionPath("projectValue", "locationValue", "sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.readSessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromReadSessionName', () => { - const result = client.matchProjectFromReadSessionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.readSessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromReadSessionName', () => { - const result = client.matchLocationFromReadSessionName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.readSessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSessionFromReadSessionName', () => { - const result = client.matchSessionFromReadSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.readSessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('stream', () => { - const fakePath = "/rendered/path/stream"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - stream: "streamValue", - }; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.streamPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.streamPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('streamPath', () => { - const result = client.streamPath("projectValue", "locationValue", "streamValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.streamPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromStreamName', () => { - const result = client.matchProjectFromStreamName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.streamPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromStreamName', () => { - const result = client.matchLocationFromStreamName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.streamPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchStreamFromStreamName', () => { - const result = client.matchStreamFromStreamName(fakePath); - assert.strictEqual(result, "streamValue"); - assert((client.pathTemplates.streamPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/package.json b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/package.json index 8a6f9cea3dc2..725beb19a1c1 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/package.json b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/package.json index d7bb5b125abf..ade3b2125601 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/package.json +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 518aecc57056..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const storage = require('storage'); - -function main() { - const bigQueryStorageClient = new storage.BigQueryStorageClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index fc714d834fb5..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {BigQueryStorageClient} from 'storage'; - -// check that the client class type name can be used -function doStuffWithBigQueryStorageClient(client: BigQueryStorageClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const bigQueryStorageClient = new BigQueryStorageClient(); - doStuffWithBigQueryStorageClient(bigQueryStorageClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/test/gapic_big_query_storage_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/test/gapic_big_query_storage_v1beta1.ts.baseline deleted file mode 100644 index 8e2bfb3d9e70..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/test/gapic_big_query_storage_v1beta1.ts.baseline +++ /dev/null @@ -1,935 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as bigquerystorageModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -describe('v1beta1.BigQueryStorageClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquerystorage.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = bigquerystorageModule.v1beta1.BigQueryStorageClient.servicePath; - assert.strictEqual(servicePath, 'bigquerystorage.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = bigquerystorageModule.v1beta1.BigQueryStorageClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquerystorage.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquerystorage.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquerystorage.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquerystorage.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquerystorage.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new bigquerystorageModule.v1beta1.BigQueryStorageClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = bigquerystorageModule.v1beta1.BigQueryStorageClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.bigQueryStorageStub, undefined); - await client.initialize(); - assert(client.bigQueryStorageStub); - }); - - it('has close method for the initialized client', done => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.bigQueryStorageStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.bigQueryStorageStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - 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); - }); - }); - - describe('createReadSession', () => { - it('invokes createReadSession without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest() - ); - request.tableReference ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'projectId']); - request.tableReference.projectId = defaultValue1; - request.tableReference ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'datasetId']); - request.tableReference.datasetId = defaultValue2; - const expectedHeaderRequestParams = `table_reference.project_id=${defaultValue1 ?? '' }&table_reference.dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadSession() - ); - client.innerApiCalls.createReadSession = stubSimpleCall(expectedResponse); - const [response] = await client.createReadSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createReadSession without error using callback', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest() - ); - request.tableReference ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'projectId']); - request.tableReference.projectId = defaultValue1; - request.tableReference ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'datasetId']); - request.tableReference.datasetId = defaultValue2; - const expectedHeaderRequestParams = `table_reference.project_id=${defaultValue1 ?? '' }&table_reference.dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadSession() - ); - client.innerApiCalls.createReadSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createReadSession( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.storage.v1beta1.IReadSession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createReadSession with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest() - ); - request.tableReference ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'projectId']); - request.tableReference.projectId = defaultValue1; - request.tableReference ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'datasetId']); - request.tableReference.datasetId = defaultValue2; - const expectedHeaderRequestParams = `table_reference.project_id=${defaultValue1 ?? '' }&table_reference.dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createReadSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createReadSession(request), expectedError); - const actualRequest = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createReadSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createReadSession with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest() - ); - request.tableReference ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'projectId']); - request.tableReference.projectId = defaultValue1; - request.tableReference ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.CreateReadSessionRequest', ['tableReference', 'datasetId']); - request.tableReference.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createReadSession(request), expectedError); - }); - }); - - describe('batchCreateReadSessionStreams', () => { - it('invokes batchCreateReadSessionStreams without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest() - ); - request.session ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest', ['session', 'name']); - request.session.name = defaultValue1; - const expectedHeaderRequestParams = `session.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsResponse() - ); - client.innerApiCalls.batchCreateReadSessionStreams = stubSimpleCall(expectedResponse); - const [response] = await client.batchCreateReadSessionStreams(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchCreateReadSessionStreams without error using callback', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest() - ); - request.session ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest', ['session', 'name']); - request.session.name = defaultValue1; - const expectedHeaderRequestParams = `session.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsResponse() - ); - client.innerApiCalls.batchCreateReadSessionStreams = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchCreateReadSessionStreams( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.storage.v1beta1.IBatchCreateReadSessionStreamsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchCreateReadSessionStreams with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest() - ); - request.session ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest', ['session', 'name']); - request.session.name = defaultValue1; - const expectedHeaderRequestParams = `session.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchCreateReadSessionStreams = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.batchCreateReadSessionStreams(request), expectedError); - const actualRequest = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchCreateReadSessionStreams as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchCreateReadSessionStreams with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest() - ); - request.session ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.BatchCreateReadSessionStreamsRequest', ['session', 'name']); - request.session.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.batchCreateReadSessionStreams(request), expectedError); - }); - }); - - describe('finalizeStream', () => { - it('invokes finalizeStream without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest() - ); - request.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest', ['stream', 'name']); - request.stream.name = defaultValue1; - const expectedHeaderRequestParams = `stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.finalizeStream = stubSimpleCall(expectedResponse); - const [response] = await client.finalizeStream(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes finalizeStream without error using callback', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest() - ); - request.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest', ['stream', 'name']); - request.stream.name = defaultValue1; - const expectedHeaderRequestParams = `stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.finalizeStream = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.finalizeStream( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes finalizeStream with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest() - ); - request.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest', ['stream', 'name']); - request.stream.name = defaultValue1; - const expectedHeaderRequestParams = `stream.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.finalizeStream = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.finalizeStream(request), expectedError); - const actualRequest = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.finalizeStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes finalizeStream with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest() - ); - request.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.FinalizeStreamRequest', ['stream', 'name']); - request.stream.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.finalizeStream(request), expectedError); - }); - }); - - describe('splitReadStream', () => { - it('invokes splitReadStream without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest() - ); - request.originalStream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest', ['originalStream', 'name']); - request.originalStream.name = defaultValue1; - const expectedHeaderRequestParams = `original_stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamResponse() - ); - client.innerApiCalls.splitReadStream = stubSimpleCall(expectedResponse); - const [response] = await client.splitReadStream(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes splitReadStream without error using callback', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest() - ); - request.originalStream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest', ['originalStream', 'name']); - request.originalStream.name = defaultValue1; - const expectedHeaderRequestParams = `original_stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamResponse() - ); - client.innerApiCalls.splitReadStream = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.splitReadStream( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.storage.v1beta1.ISplitReadStreamResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes splitReadStream with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest() - ); - request.originalStream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest', ['originalStream', 'name']); - request.originalStream.name = defaultValue1; - const expectedHeaderRequestParams = `original_stream.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.splitReadStream = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.splitReadStream(request), expectedError); - const actualRequest = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.splitReadStream as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes splitReadStream with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest() - ); - request.originalStream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.SplitReadStreamRequest', ['originalStream', 'name']); - request.originalStream.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.splitReadStream(request), expectedError); - }); - }); - - describe('readRows', () => { - it('invokes readRows without error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest() - ); - request.readPosition ??= {}; - request.readPosition.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']); - request.readPosition.stream.name = defaultValue1; - const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse() - ); - client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse); - const stream = client.readRows(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes readRows without error and gaxServerStreamingRetries enabled', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest() - ); - request.readPosition ??= {}; - request.readPosition.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']); - request.readPosition.stream.name = defaultValue1; - const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse() - ); - client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse); - const stream = client.readRows(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes readRows with error', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest() - ); - request.readPosition ??= {}; - request.readPosition.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']); - request.readPosition.stream.name = defaultValue1; - const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.readRows = stubServerStreamingCall(undefined, expectedError); - const stream = client.readRows(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.readRows as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes readRows with closed client', async () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest() - ); - request.readPosition ??= {}; - request.readPosition.stream ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']); - request.readPosition.stream.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.readRows(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('Path templates', () => { - - describe('readSession', async () => { - const fakePath = "/rendered/path/readSession"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - session: "sessionValue", - }; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.readSessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.readSessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('readSessionPath', () => { - const result = client.readSessionPath("projectValue", "locationValue", "sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.readSessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromReadSessionName', () => { - const result = client.matchProjectFromReadSessionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.readSessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromReadSessionName', () => { - const result = client.matchLocationFromReadSessionName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.readSessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSessionFromReadSessionName', () => { - const result = client.matchSessionFromReadSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.readSessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('stream', async () => { - const fakePath = "/rendered/path/stream"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - stream: "streamValue", - }; - const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.streamPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.streamPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('streamPath', () => { - const result = client.streamPath("projectValue", "locationValue", "streamValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.streamPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromStreamName', () => { - const result = client.matchProjectFromStreamName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.streamPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromStreamName', () => { - const result = client.matchLocationFromStreamName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.streamPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchStreamFromStreamName', () => { - const result = client.matchStreamFromStreamName(fakePath); - assert.strictEqual(result, "streamValue"); - assert((client.pathTemplates.streamPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-storage/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-storage/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 788c2d2a9880..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const bigquery = require('bigquery'); - -function main() { - const datasetServiceClient = new bigquery.DatasetServiceClient(); - const jobServiceClient = new bigquery.JobServiceClient(); - const modelServiceClient = new bigquery.ModelServiceClient(); - const projectServiceClient = new bigquery.ProjectServiceClient(); - const routineServiceClient = new bigquery.RoutineServiceClient(); - const rowAccessPolicyServiceClient = new bigquery.RowAccessPolicyServiceClient(); - const tableServiceClient = new bigquery.TableServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 3e5a9a70a773..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as bigquery from 'bigquery'; - -function main() { - const datasetServiceClient = new bigquery.DatasetServiceClient(); - const jobServiceClient = new bigquery.JobServiceClient(); - const modelServiceClient = new bigquery.ModelServiceClient(); - const projectServiceClient = new bigquery.ProjectServiceClient(); - const routineServiceClient = new bigquery.RoutineServiceClient(); - const rowAccessPolicyServiceClient = new bigquery.RowAccessPolicyServiceClient(); - const tableServiceClient = new bigquery.TableServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 029845840670..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,69 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {DatasetServiceClient, JobServiceClient, ModelServiceClient, ProjectServiceClient, RoutineServiceClient, RowAccessPolicyServiceClient, TableServiceClient} from 'bigquery'; - -// check that the client class type name can be used -function doStuffWithDatasetServiceClient(client: DatasetServiceClient) { - client.close(); -} -function doStuffWithJobServiceClient(client: JobServiceClient) { - client.close(); -} -function doStuffWithModelServiceClient(client: ModelServiceClient) { - client.close(); -} -function doStuffWithProjectServiceClient(client: ProjectServiceClient) { - client.close(); -} -function doStuffWithRoutineServiceClient(client: RoutineServiceClient) { - client.close(); -} -function doStuffWithRowAccessPolicyServiceClient(client: RowAccessPolicyServiceClient) { - client.close(); -} -function doStuffWithTableServiceClient(client: TableServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const datasetServiceClient = new DatasetServiceClient(); - doStuffWithDatasetServiceClient(datasetServiceClient); - // check that the client instance can be created - const jobServiceClient = new JobServiceClient(); - doStuffWithJobServiceClient(jobServiceClient); - // check that the client instance can be created - const modelServiceClient = new ModelServiceClient(); - doStuffWithModelServiceClient(modelServiceClient); - // check that the client instance can be created - const projectServiceClient = new ProjectServiceClient(); - doStuffWithProjectServiceClient(projectServiceClient); - // check that the client instance can be created - const routineServiceClient = new RoutineServiceClient(); - doStuffWithRoutineServiceClient(routineServiceClient); - // check that the client instance can be created - const rowAccessPolicyServiceClient = new RowAccessPolicyServiceClient(); - doStuffWithRowAccessPolicyServiceClient(rowAccessPolicyServiceClient); - // check that the client instance can be created - const tableServiceClient = new TableServiceClient(); - doStuffWithTableServiceClient(tableServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_dataset_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_dataset_service_v2.ts.baseline deleted file mode 100644 index acb509629be1..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_dataset_service_v2.ts.baseline +++ /dev/null @@ -1,1223 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as datasetserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.DatasetServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = datasetserviceModule.v2.DatasetServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = datasetserviceModule.v2.DatasetServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new datasetserviceModule.v2.DatasetServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new datasetserviceModule.v2.DatasetServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new datasetserviceModule.v2.DatasetServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = datasetserviceModule.v2.DatasetServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.datasetServiceStub, undefined); - await client.initialize(); - assert(client.datasetServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.datasetServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.datasetServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new datasetserviceModule.v2.DatasetServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new datasetserviceModule.v2.DatasetServiceClient({ - 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); - }); - }); - - describe('getDataset', () => { - it('invokes getDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.getDataset = stubSimpleCall(expectedResponse); - const [response] = await client.getDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.getDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDataset(request), expectedError); - }); - }); - - describe('insertDataset', () => { - it('invokes insertDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.insertDataset = stubSimpleCall(expectedResponse); - const [response] = await client.insertDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.insertDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insertDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insertDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insertDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insertDataset(request), expectedError); - }); - }); - - describe('patchDataset', () => { - it('invokes patchDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.patchDataset = stubSimpleCall(expectedResponse); - const [response] = await client.patchDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.patchDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patchDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patchDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patchDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patchDataset(request), expectedError); - }); - }); - - describe('updateDataset', () => { - it('invokes updateDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.updateDataset = stubSimpleCall(expectedResponse); - const [response] = await client.updateDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.updateDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateDataset(request), expectedError); - }); - }); - - describe('deleteDataset', () => { - it('invokes deleteDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDataset = stubSimpleCall(expectedResponse); - const [response] = await client.deleteDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDataset( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteDataset(request), expectedError); - }); - }); - - describe('undeleteDataset', () => { - it('invokes undeleteDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UndeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.undeleteDataset = stubSimpleCall(expectedResponse); - const [response] = await client.undeleteDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UndeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.undeleteDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.undeleteDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UndeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.undeleteDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.undeleteDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UndeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.undeleteDataset(request), expectedError); - }); - }); - - describe('listDatasets', () => { - it('invokes listDatasets without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - ]; - client.innerApiCalls.listDatasets = stubSimpleCall(expectedResponse); - const [response] = await client.listDatasets(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatasets without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - ]; - client.innerApiCalls.listDatasets = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDatasets( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IListFormatDataset[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatasets with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDatasets = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listDatasets(request), expectedError); - const actualRequest = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatasetsStream without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - ]; - client.descriptors.page.listDatasets.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listDatasetsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatDataset[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatDataset) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listDatasets.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDatasets, request)); - assert( - (client.descriptors.page.listDatasets.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listDatasetsStream with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDatasets.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listDatasetsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatDataset[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatDataset) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listDatasets.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDatasets, request)); - assert( - (client.descriptors.page.listDatasets.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDatasets without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - ]; - client.descriptors.page.listDatasets.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IListFormatDataset[] = []; - const iterable = client.listDatasetsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listDatasets.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDatasets.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDatasets with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDatasets.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listDatasetsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IListFormatDataset[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listDatasets.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDatasets.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_job_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_job_service_v2.ts.baseline deleted file mode 100644 index 73f32ed3eed7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_job_service_v2.ts.baseline +++ /dev/null @@ -1,1211 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as jobserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.JobServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new jobserviceModule.v2.JobServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new jobserviceModule.v2.JobServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = jobserviceModule.v2.JobServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = jobserviceModule.v2.JobServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new jobserviceModule.v2.JobServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new jobserviceModule.v2.JobServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new jobserviceModule.v2.JobServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new jobserviceModule.v2.JobServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new jobserviceModule.v2.JobServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = jobserviceModule.v2.JobServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new jobserviceModule.v2.JobServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new jobserviceModule.v2.JobServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.jobServiceStub, undefined); - await client.initialize(); - assert(client.jobServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.jobServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.jobServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new jobserviceModule.v2.JobServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new jobserviceModule.v2.JobServiceClient({ - 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); - }); - }); - - describe('cancelJob', () => { - it('invokes cancelJob without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.CancelJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.JobCancelResponse() - ); - client.innerApiCalls.cancelJob = stubSimpleCall(expectedResponse); - const [response] = await client.cancelJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelJob without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.CancelJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.JobCancelResponse() - ); - client.innerApiCalls.cancelJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.cancelJob( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IJobCancelResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelJob with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.CancelJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.cancelJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.cancelJob(request), expectedError); - const actualRequest = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelJob with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.CancelJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.cancelJob(request), expectedError); - }); - }); - - describe('getJob', () => { - it('invokes getJob without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Job() - ); - client.innerApiCalls.getJob = stubSimpleCall(expectedResponse); - const [response] = await client.getJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJob without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Job() - ); - client.innerApiCalls.getJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getJob( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJob with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getJob(request), expectedError); - const actualRequest = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJob with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getJob(request), expectedError); - }); - }); - - describe('insertJob', () => { - it('invokes insertJob without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertJobRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Job() - ); - client.innerApiCalls.insertJob = stubSimpleCall(expectedResponse); - const [response] = await client.insertJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertJob without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertJobRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Job() - ); - client.innerApiCalls.insertJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insertJob( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertJob with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertJobRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insertJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insertJob(request), expectedError); - const actualRequest = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertJob with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertJobRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insertJob(request), expectedError); - }); - }); - - describe('deleteJob', () => { - it('invokes deleteJob without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteJob = stubSimpleCall(expectedResponse); - const [response] = await client.deleteJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJob without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteJob( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJob with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteJob(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJob with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteJob(request), expectedError); - }); - }); - - describe('getQueryResults', () => { - it('invokes getQueryResults without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsResponse() - ); - client.innerApiCalls.getQueryResults = stubSimpleCall(expectedResponse); - const [response] = await client.getQueryResults(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueryResults without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsResponse() - ); - client.innerApiCalls.getQueryResults = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getQueryResults( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IGetQueryResultsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueryResults with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getQueryResults = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getQueryResults(request), expectedError); - const actualRequest = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueryResults with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getQueryResults(request), expectedError); - }); - }); - - describe('query', () => { - it('invokes query without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PostQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PostQueryRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.QueryResponse() - ); - client.innerApiCalls.query = stubSimpleCall(expectedResponse); - const [response] = await client.query(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes query without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PostQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PostQueryRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.QueryResponse() - ); - client.innerApiCalls.query = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.query( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IQueryResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes query with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PostQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PostQueryRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.query = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.query(request), expectedError); - const actualRequest = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes query with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PostQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PostQueryRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.query(request), expectedError); - }); - }); - - describe('listJobs', () => { - it('invokes listJobs without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - ]; - client.innerApiCalls.listJobs = stubSimpleCall(expectedResponse); - const [response] = await client.listJobs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobs without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - ]; - client.innerApiCalls.listJobs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listJobs( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IListFormatJob[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobs with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listJobs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listJobs(request), expectedError); - const actualRequest = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobsStream without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - ]; - client.descriptors.page.listJobs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatJob[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listJobs, request)); - assert( - (client.descriptors.page.listJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listJobsStream with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listJobs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatJob[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listJobs, request)); - assert( - (client.descriptors.page.listJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listJobs without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - ]; - client.descriptors.page.listJobs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IListFormatJob[] = []; - const iterable = client.listJobsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listJobs with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listJobs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listJobsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IListFormatJob[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_model_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_model_service_v2.ts.baseline deleted file mode 100644 index 661cc4afcc9b..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_model_service_v2.ts.baseline +++ /dev/null @@ -1,932 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as modelserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.ModelServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new modelserviceModule.v2.ModelServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new modelserviceModule.v2.ModelServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = modelserviceModule.v2.ModelServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = modelserviceModule.v2.ModelServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new modelserviceModule.v2.ModelServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new modelserviceModule.v2.ModelServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new modelserviceModule.v2.ModelServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new modelserviceModule.v2.ModelServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new modelserviceModule.v2.ModelServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = modelserviceModule.v2.ModelServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new modelserviceModule.v2.ModelServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.modelServiceStub, undefined); - await client.initialize(); - assert(client.modelServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.modelServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.modelServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new modelserviceModule.v2.ModelServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new modelserviceModule.v2.ModelServiceClient({ - 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); - }); - }); - - describe('getModel', () => { - it('invokes getModel without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Model() - ); - client.innerApiCalls.getModel = stubSimpleCall(expectedResponse); - const [response] = await client.getModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel without error using callback', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Model() - ); - client.innerApiCalls.getModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getModel( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getModel(request), expectedError); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel with closed client', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getModel(request), expectedError); - }); - }); - - describe('patchModel', () => { - it('invokes patchModel without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Model() - ); - client.innerApiCalls.patchModel = stubSimpleCall(expectedResponse); - const [response] = await client.patchModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchModel without error using callback', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Model() - ); - client.innerApiCalls.patchModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patchModel( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchModel with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patchModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patchModel(request), expectedError); - const actualRequest = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchModel with closed client', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patchModel(request), expectedError); - }); - }); - - describe('deleteModel', () => { - it('invokes deleteModel without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteModel = stubSimpleCall(expectedResponse); - const [response] = await client.deleteModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel without error using callback', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteModel( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteModel(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel with closed client', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteModel(request), expectedError); - }); - }); - - describe('listModels', () => { - it('invokes listModels without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - ]; - client.innerApiCalls.listModels = stubSimpleCall(expectedResponse); - const [response] = await client.listModels(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModels without error using callback', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - ]; - client.innerApiCalls.listModels = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listModels( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IModel[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModels with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listModels = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listModels(request), expectedError); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModelsStream without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - ]; - client.descriptors.page.listModels.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listModelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.Model[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.Model) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listModels, request)); - assert( - (client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listModelsStream with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listModels.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listModelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.Model[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.Model) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listModels, request)); - assert( - (client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listModels without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - ]; - client.descriptors.page.listModels.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IModel[] = []; - const iterable = client.listModelsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listModels with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listModels.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listModelsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IModel[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_project_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_project_service_v2.ts.baseline deleted file mode 100644 index 1c8e45afa4b4..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_project_service_v2.ts.baseline +++ /dev/null @@ -1,331 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as projectserviceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v2.ProjectServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new projectserviceModule.v2.ProjectServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new projectserviceModule.v2.ProjectServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = projectserviceModule.v2.ProjectServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = projectserviceModule.v2.ProjectServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new projectserviceModule.v2.ProjectServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new projectserviceModule.v2.ProjectServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new projectserviceModule.v2.ProjectServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new projectserviceModule.v2.ProjectServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new projectserviceModule.v2.ProjectServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = projectserviceModule.v2.ProjectServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new projectserviceModule.v2.ProjectServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.projectServiceStub, undefined); - await client.initialize(); - assert(client.projectServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.projectServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.projectServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new projectserviceModule.v2.ProjectServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new projectserviceModule.v2.ProjectServiceClient({ - 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); - }); - }); - - describe('getServiceAccount', () => { - it('invokes getServiceAccount without error', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetServiceAccountRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountResponse() - ); - client.innerApiCalls.getServiceAccount = stubSimpleCall(expectedResponse); - const [response] = await client.getServiceAccount(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceAccount without error using callback', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetServiceAccountRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountResponse() - ); - client.innerApiCalls.getServiceAccount = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getServiceAccount( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IGetServiceAccountResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceAccount with error', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetServiceAccountRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getServiceAccount = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getServiceAccount(request), expectedError); - const actualRequest = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceAccount with closed client', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetServiceAccountRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getServiceAccount(request), expectedError); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_routine_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_routine_service_v2.ts.baseline deleted file mode 100644 index d27f1fedb882..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_routine_service_v2.ts.baseline +++ /dev/null @@ -1,1127 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as routineserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.RoutineServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new routineserviceModule.v2.RoutineServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new routineserviceModule.v2.RoutineServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = routineserviceModule.v2.RoutineServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = routineserviceModule.v2.RoutineServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new routineserviceModule.v2.RoutineServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new routineserviceModule.v2.RoutineServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new routineserviceModule.v2.RoutineServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new routineserviceModule.v2.RoutineServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new routineserviceModule.v2.RoutineServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = routineserviceModule.v2.RoutineServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new routineserviceModule.v2.RoutineServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.routineServiceStub, undefined); - await client.initialize(); - assert(client.routineServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.routineServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.routineServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new routineserviceModule.v2.RoutineServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new routineserviceModule.v2.RoutineServiceClient({ - 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); - }); - }); - - describe('getRoutine', () => { - it('invokes getRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.getRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.getRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.getRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getRoutine( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getRoutine(request), expectedError); - const actualRequest = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getRoutine(request), expectedError); - }); - }); - - describe('insertRoutine', () => { - it('invokes insertRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.insertRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.insertRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.insertRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insertRoutine( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insertRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insertRoutine(request), expectedError); - const actualRequest = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insertRoutine(request), expectedError); - }); - }); - - describe('updateRoutine', () => { - it('invokes updateRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.updateRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.updateRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.updateRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateRoutine( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateRoutine(request), expectedError); - const actualRequest = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateRoutine(request), expectedError); - }); - }); - - describe('patchRoutine', () => { - it('invokes patchRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchRoutineRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.patchRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.patchRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes patchRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchRoutineRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.patchRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patchRoutine( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes patchRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchRoutineRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.patchRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patchRoutine(request), expectedError); - }); - - it('invokes patchRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchRoutineRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patchRoutine(request), expectedError); - }); - }); - - describe('deleteRoutine', () => { - it('invokes deleteRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.deleteRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteRoutine( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteRoutine(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteRoutine(request), expectedError); - }); - }); - - describe('listRoutines', () => { - it('invokes listRoutines without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - ]; - client.innerApiCalls.listRoutines = stubSimpleCall(expectedResponse); - const [response] = await client.listRoutines(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRoutines without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - ]; - client.innerApiCalls.listRoutines = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listRoutines( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRoutines with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listRoutines = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listRoutines(request), expectedError); - const actualRequest = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRoutinesStream without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - ]; - client.descriptors.page.listRoutines.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listRoutinesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.Routine[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.Routine) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listRoutines.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRoutines, request)); - assert( - (client.descriptors.page.listRoutines.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listRoutinesStream with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listRoutines.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listRoutinesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.Routine[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.Routine) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listRoutines.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRoutines, request)); - assert( - (client.descriptors.page.listRoutines.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listRoutines without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - ]; - client.descriptors.page.listRoutines.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IRoutine[] = []; - const iterable = client.listRoutinesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRoutines.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listRoutines.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listRoutines with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listRoutines.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listRoutinesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IRoutine[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRoutines.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listRoutines.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_row_access_policy_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_row_access_policy_service_v2.ts.baseline deleted file mode 100644 index 3691314bc19e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_row_access_policy_service_v2.ts.baseline +++ /dev/null @@ -1,557 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as rowaccesspolicyserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.RowAccessPolicyServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.rowAccessPolicyServiceStub, undefined); - await client.initialize(); - assert(client.rowAccessPolicyServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.rowAccessPolicyServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.rowAccessPolicyServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - 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); - }); - }); - - describe('listRowAccessPolicies', () => { - it('invokes listRowAccessPolicies without error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - ]; - client.innerApiCalls.listRowAccessPolicies = stubSimpleCall(expectedResponse); - const [response] = await client.listRowAccessPolicies(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRowAccessPolicies without error using callback', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - ]; - client.innerApiCalls.listRowAccessPolicies = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listRowAccessPolicies( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRowAccessPolicy[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRowAccessPolicies with error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listRowAccessPolicies = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listRowAccessPolicies(request), expectedError); - const actualRequest = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRowAccessPoliciesStream without error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - ]; - client.descriptors.page.listRowAccessPolicies.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listRowAccessPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.RowAccessPolicy[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.RowAccessPolicy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listRowAccessPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRowAccessPolicies, request)); - assert( - (client.descriptors.page.listRowAccessPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listRowAccessPoliciesStream with error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listRowAccessPolicies.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listRowAccessPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.RowAccessPolicy[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.RowAccessPolicy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listRowAccessPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRowAccessPolicies, request)); - assert( - (client.descriptors.page.listRowAccessPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listRowAccessPolicies without error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - ]; - client.descriptors.page.listRowAccessPolicies.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IRowAccessPolicy[] = []; - const iterable = client.listRowAccessPoliciesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRowAccessPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listRowAccessPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listRowAccessPolicies with error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listRowAccessPolicies.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listRowAccessPoliciesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IRowAccessPolicy[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRowAccessPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listRowAccessPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_table_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_table_service_v2.ts.baseline deleted file mode 100644 index ee2194fd6ce1..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/esm/test/gapic_table_service_v2.ts.baseline +++ /dev/null @@ -1,1184 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as tableserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.TableServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new tableserviceModule.v2.TableServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new tableserviceModule.v2.TableServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = tableserviceModule.v2.TableServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = tableserviceModule.v2.TableServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new tableserviceModule.v2.TableServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new tableserviceModule.v2.TableServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new tableserviceModule.v2.TableServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new tableserviceModule.v2.TableServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new tableserviceModule.v2.TableServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = tableserviceModule.v2.TableServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new tableserviceModule.v2.TableServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new tableserviceModule.v2.TableServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.tableServiceStub, undefined); - await client.initialize(); - assert(client.tableServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.tableServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.tableServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new tableserviceModule.v2.TableServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new tableserviceModule.v2.TableServiceClient({ - 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); - }); - }); - - describe('getTable', () => { - it('invokes getTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.getTable = stubSimpleCall(expectedResponse); - const [response] = await client.getTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.getTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getTable( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.ITable|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getTable(request), expectedError); - const actualRequest = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getTable(request), expectedError); - }); - }); - - describe('insertTable', () => { - it('invokes insertTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.insertTable = stubSimpleCall(expectedResponse); - const [response] = await client.insertTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.insertTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insertTable( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.ITable|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insertTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insertTable(request), expectedError); - const actualRequest = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insertTable(request), expectedError); - }); - }); - - describe('patchTable', () => { - it('invokes patchTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.patchTable = stubSimpleCall(expectedResponse); - const [response] = await client.patchTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.patchTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patchTable( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.ITable|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patchTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patchTable(request), expectedError); - const actualRequest = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patchTable(request), expectedError); - }); - }); - - describe('updateTable', () => { - it('invokes updateTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.updateTable = stubSimpleCall(expectedResponse); - const [response] = await client.updateTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.updateTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateTable( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.ITable|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateTable(request), expectedError); - const actualRequest = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateTable(request), expectedError); - }); - }); - - describe('deleteTable', () => { - it('invokes deleteTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTable = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTable( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTable(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteTable(request), expectedError); - }); - }); - - describe('listTables', () => { - it('invokes listTables without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - ]; - client.innerApiCalls.listTables = stubSimpleCall(expectedResponse); - const [response] = await client.listTables(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTables without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - ]; - client.innerApiCalls.listTables = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTables( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IListFormatTable[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTables with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTables = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTables(request), expectedError); - const actualRequest = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTablesStream without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - ]; - client.descriptors.page.listTables.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTablesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatTable[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatTable) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTables.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTables, request)); - assert( - (client.descriptors.page.listTables.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTablesStream with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTables.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTablesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatTable[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatTable) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTables.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTables, request)); - assert( - (client.descriptors.page.listTables.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTables without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - ]; - client.descriptors.page.listTables.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IListFormatTable[] = []; - const iterable = client.listTablesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTables.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTables.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTables with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTables.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTablesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IListFormatTable[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTables.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTables.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/package.json b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/package.json index 39b7ea64a005..c4350b8803fe 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/package.json @@ -66,12 +66,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -86,21 +80,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/package.json b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/package.json index d4c98eed0cc8..9fcd0e7673d4 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/package.json +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/package.json @@ -36,27 +36,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index f4b165acfaf1..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const bigquery = require('bigquery'); - -function main() { - const datasetServiceClient = new bigquery.DatasetServiceClient(); - const jobServiceClient = new bigquery.JobServiceClient(); - const modelServiceClient = new bigquery.ModelServiceClient(); - const projectServiceClient = new bigquery.ProjectServiceClient(); - const routineServiceClient = new bigquery.RoutineServiceClient(); - const rowAccessPolicyServiceClient = new bigquery.RowAccessPolicyServiceClient(); - const tableServiceClient = new bigquery.TableServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index d6c84c7fbbec..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {DatasetServiceClient, JobServiceClient, ModelServiceClient, ProjectServiceClient, RoutineServiceClient, RowAccessPolicyServiceClient, TableServiceClient} from 'bigquery'; - -// check that the client class type name can be used -function doStuffWithDatasetServiceClient(client: DatasetServiceClient) { - client.close(); -} -function doStuffWithJobServiceClient(client: JobServiceClient) { - client.close(); -} -function doStuffWithModelServiceClient(client: ModelServiceClient) { - client.close(); -} -function doStuffWithProjectServiceClient(client: ProjectServiceClient) { - client.close(); -} -function doStuffWithRoutineServiceClient(client: RoutineServiceClient) { - client.close(); -} -function doStuffWithRowAccessPolicyServiceClient(client: RowAccessPolicyServiceClient) { - client.close(); -} -function doStuffWithTableServiceClient(client: TableServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const datasetServiceClient = new DatasetServiceClient(); - doStuffWithDatasetServiceClient(datasetServiceClient); - // check that the client instance can be created - const jobServiceClient = new JobServiceClient(); - doStuffWithJobServiceClient(jobServiceClient); - // check that the client instance can be created - const modelServiceClient = new ModelServiceClient(); - doStuffWithModelServiceClient(modelServiceClient); - // check that the client instance can be created - const projectServiceClient = new ProjectServiceClient(); - doStuffWithProjectServiceClient(projectServiceClient); - // check that the client instance can be created - const routineServiceClient = new RoutineServiceClient(); - doStuffWithRoutineServiceClient(routineServiceClient); - // check that the client instance can be created - const rowAccessPolicyServiceClient = new RowAccessPolicyServiceClient(); - doStuffWithRowAccessPolicyServiceClient(rowAccessPolicyServiceClient); - // check that the client instance can be created - const tableServiceClient = new TableServiceClient(); - doStuffWithTableServiceClient(tableServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_dataset_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_dataset_service_v2.ts.baseline deleted file mode 100644 index be0cee887bc6..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_dataset_service_v2.ts.baseline +++ /dev/null @@ -1,1214 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as datasetserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.DatasetServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = datasetserviceModule.v2.DatasetServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = datasetserviceModule.v2.DatasetServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new datasetserviceModule.v2.DatasetServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new datasetserviceModule.v2.DatasetServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new datasetserviceModule.v2.DatasetServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = datasetserviceModule.v2.DatasetServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.datasetServiceStub, undefined); - await client.initialize(); - assert(client.datasetServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.datasetServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.datasetServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new datasetserviceModule.v2.DatasetServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new datasetserviceModule.v2.DatasetServiceClient({ - 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); - }); - }); - - describe('getDataset', () => { - it('invokes getDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.getDataset = stubSimpleCall(expectedResponse); - const [response] = await client.getDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.getDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDataset(request), expectedError); - }); - }); - - describe('insertDataset', () => { - it('invokes insertDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.insertDataset = stubSimpleCall(expectedResponse); - const [response] = await client.insertDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.insertDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insertDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insertDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insertDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insertDataset(request), expectedError); - }); - }); - - describe('patchDataset', () => { - it('invokes patchDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.patchDataset = stubSimpleCall(expectedResponse); - const [response] = await client.patchDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.patchDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patchDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patchDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patchDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patchDataset(request), expectedError); - }); - }); - - describe('updateDataset', () => { - it('invokes updateDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.updateDataset = stubSimpleCall(expectedResponse); - const [response] = await client.updateDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.updateDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateDataset(request), expectedError); - }); - }); - - describe('deleteDataset', () => { - it('invokes deleteDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDataset = stubSimpleCall(expectedResponse); - const [response] = await client.deleteDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDataset( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteDataset(request), expectedError); - }); - }); - - describe('undeleteDataset', () => { - it('invokes undeleteDataset without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UndeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.undeleteDataset = stubSimpleCall(expectedResponse); - const [response] = await client.undeleteDataset(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteDataset without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UndeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Dataset() - ); - client.innerApiCalls.undeleteDataset = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.undeleteDataset( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IDataset|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteDataset with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UndeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.undeleteDataset = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.undeleteDataset(request), expectedError); - const actualRequest = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteDataset as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteDataset with closed client', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UndeleteDatasetRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UndeleteDatasetRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.undeleteDataset(request), expectedError); - }); - }); - - describe('listDatasets', () => { - it('invokes listDatasets without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - ]; - client.innerApiCalls.listDatasets = stubSimpleCall(expectedResponse); - const [response] = await client.listDatasets(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatasets without error using callback', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - ]; - client.innerApiCalls.listDatasets = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDatasets( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IListFormatDataset[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatasets with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDatasets = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listDatasets(request), expectedError); - const actualRequest = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDatasets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDatasetsStream without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - ]; - client.descriptors.page.listDatasets.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listDatasetsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatDataset[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatDataset) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listDatasets.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDatasets, request)); - assert( - (client.descriptors.page.listDatasets.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listDatasetsStream with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDatasets.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listDatasetsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatDataset[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatDataset) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listDatasets.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDatasets, request)); - assert( - (client.descriptors.page.listDatasets.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDatasets without error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatDataset()), - ]; - client.descriptors.page.listDatasets.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IListFormatDataset[] = []; - const iterable = client.listDatasetsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listDatasets.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDatasets.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDatasets with error', async () => { - const client = new datasetserviceModule.v2.DatasetServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListDatasetsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListDatasetsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDatasets.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listDatasetsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IListFormatDataset[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listDatasets.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDatasets.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_job_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_job_service_v2.ts.baseline deleted file mode 100644 index 0799090ee38c..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_job_service_v2.ts.baseline +++ /dev/null @@ -1,1202 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as jobserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.JobServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new jobserviceModule.v2.JobServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new jobserviceModule.v2.JobServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = jobserviceModule.v2.JobServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = jobserviceModule.v2.JobServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new jobserviceModule.v2.JobServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new jobserviceModule.v2.JobServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new jobserviceModule.v2.JobServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new jobserviceModule.v2.JobServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new jobserviceModule.v2.JobServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = jobserviceModule.v2.JobServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new jobserviceModule.v2.JobServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new jobserviceModule.v2.JobServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.jobServiceStub, undefined); - await client.initialize(); - assert(client.jobServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.jobServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.jobServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new jobserviceModule.v2.JobServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new jobserviceModule.v2.JobServiceClient({ - 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); - }); - }); - - describe('cancelJob', () => { - it('invokes cancelJob without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.CancelJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.JobCancelResponse() - ); - client.innerApiCalls.cancelJob = stubSimpleCall(expectedResponse); - const [response] = await client.cancelJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelJob without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.CancelJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.JobCancelResponse() - ); - client.innerApiCalls.cancelJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.cancelJob( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IJobCancelResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelJob with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.CancelJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.cancelJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.cancelJob(request), expectedError); - const actualRequest = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelJob with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.CancelJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.CancelJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.cancelJob(request), expectedError); - }); - }); - - describe('getJob', () => { - it('invokes getJob without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Job() - ); - client.innerApiCalls.getJob = stubSimpleCall(expectedResponse); - const [response] = await client.getJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJob without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Job() - ); - client.innerApiCalls.getJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getJob( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJob with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getJob(request), expectedError); - const actualRequest = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJob with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getJob(request), expectedError); - }); - }); - - describe('insertJob', () => { - it('invokes insertJob without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertJobRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Job() - ); - client.innerApiCalls.insertJob = stubSimpleCall(expectedResponse); - const [response] = await client.insertJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertJob without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertJobRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Job() - ); - client.innerApiCalls.insertJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insertJob( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertJob with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertJobRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insertJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insertJob(request), expectedError); - const actualRequest = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertJob with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertJobRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insertJob(request), expectedError); - }); - }); - - describe('deleteJob', () => { - it('invokes deleteJob without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteJob = stubSimpleCall(expectedResponse); - const [response] = await client.deleteJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJob without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteJob( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJob with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteJob(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJob with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteJobRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteJob(request), expectedError); - }); - }); - - describe('getQueryResults', () => { - it('invokes getQueryResults without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsResponse() - ); - client.innerApiCalls.getQueryResults = stubSimpleCall(expectedResponse); - const [response] = await client.getQueryResults(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueryResults without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsResponse() - ); - client.innerApiCalls.getQueryResults = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getQueryResults( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IGetQueryResultsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueryResults with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&job_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getQueryResults = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getQueryResults(request), expectedError); - const actualRequest = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueryResults as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueryResults with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetQueryResultsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetQueryResultsRequest', ['jobId']); - request.jobId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getQueryResults(request), expectedError); - }); - }); - - describe('query', () => { - it('invokes query without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PostQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PostQueryRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.QueryResponse() - ); - client.innerApiCalls.query = stubSimpleCall(expectedResponse); - const [response] = await client.query(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes query without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PostQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PostQueryRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.QueryResponse() - ); - client.innerApiCalls.query = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.query( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IQueryResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes query with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PostQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PostQueryRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.query = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.query(request), expectedError); - const actualRequest = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.query as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes query with closed client', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PostQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PostQueryRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.query(request), expectedError); - }); - }); - - describe('listJobs', () => { - it('invokes listJobs without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - ]; - client.innerApiCalls.listJobs = stubSimpleCall(expectedResponse); - const [response] = await client.listJobs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobs without error using callback', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - ]; - client.innerApiCalls.listJobs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listJobs( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IListFormatJob[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobs with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listJobs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listJobs(request), expectedError); - const actualRequest = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobsStream without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - ]; - client.descriptors.page.listJobs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatJob[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listJobs, request)); - assert( - (client.descriptors.page.listJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listJobsStream with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listJobs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatJob[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listJobs, request)); - assert( - (client.descriptors.page.listJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listJobs without error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatJob()), - ]; - client.descriptors.page.listJobs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IListFormatJob[] = []; - const iterable = client.listJobsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listJobs with error', async () => { - const client = new jobserviceModule.v2.JobServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListJobsRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listJobs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listJobsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IListFormatJob[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_model_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_model_service_v2.ts.baseline deleted file mode 100644 index 5450fa40562c..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_model_service_v2.ts.baseline +++ /dev/null @@ -1,923 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as modelserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.ModelServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new modelserviceModule.v2.ModelServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new modelserviceModule.v2.ModelServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = modelserviceModule.v2.ModelServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = modelserviceModule.v2.ModelServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new modelserviceModule.v2.ModelServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new modelserviceModule.v2.ModelServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new modelserviceModule.v2.ModelServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new modelserviceModule.v2.ModelServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new modelserviceModule.v2.ModelServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = modelserviceModule.v2.ModelServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new modelserviceModule.v2.ModelServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.modelServiceStub, undefined); - await client.initialize(); - assert(client.modelServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.modelServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.modelServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new modelserviceModule.v2.ModelServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new modelserviceModule.v2.ModelServiceClient({ - 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); - }); - }); - - describe('getModel', () => { - it('invokes getModel without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Model() - ); - client.innerApiCalls.getModel = stubSimpleCall(expectedResponse); - const [response] = await client.getModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel without error using callback', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Model() - ); - client.innerApiCalls.getModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getModel( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getModel(request), expectedError); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel with closed client', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getModel(request), expectedError); - }); - }); - - describe('patchModel', () => { - it('invokes patchModel without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Model() - ); - client.innerApiCalls.patchModel = stubSimpleCall(expectedResponse); - const [response] = await client.patchModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchModel without error using callback', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Model() - ); - client.innerApiCalls.patchModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patchModel( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchModel with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patchModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patchModel(request), expectedError); - const actualRequest = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchModel with closed client', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.PatchModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patchModel(request), expectedError); - }); - }); - - describe('deleteModel', () => { - it('invokes deleteModel without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteModel = stubSimpleCall(expectedResponse); - const [response] = await client.deleteModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel without error using callback', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteModel( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&model_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteModel(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel with closed client', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteModelRequest', ['modelId']); - request.modelId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteModel(request), expectedError); - }); - }); - - describe('listModels', () => { - it('invokes listModels without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - ]; - client.innerApiCalls.listModels = stubSimpleCall(expectedResponse); - const [response] = await client.listModels(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModels without error using callback', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - ]; - client.innerApiCalls.listModels = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listModels( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IModel[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModels with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listModels = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listModels(request), expectedError); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModelsStream without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - ]; - client.descriptors.page.listModels.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listModelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.Model[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.Model) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listModels, request)); - assert( - (client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listModelsStream with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listModels.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listModelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.Model[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.Model) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listModels, request)); - assert( - (client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listModels without error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Model()), - ]; - client.descriptors.page.listModels.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IModel[] = []; - const iterable = client.listModelsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listModels with error', async () => { - const client = new modelserviceModule.v2.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListModelsRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listModels.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listModelsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IModel[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_project_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_project_service_v2.ts.baseline deleted file mode 100644 index 4db88866c85f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_project_service_v2.ts.baseline +++ /dev/null @@ -1,322 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as projectserviceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v2.ProjectServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new projectserviceModule.v2.ProjectServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new projectserviceModule.v2.ProjectServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = projectserviceModule.v2.ProjectServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = projectserviceModule.v2.ProjectServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new projectserviceModule.v2.ProjectServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new projectserviceModule.v2.ProjectServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new projectserviceModule.v2.ProjectServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new projectserviceModule.v2.ProjectServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new projectserviceModule.v2.ProjectServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = projectserviceModule.v2.ProjectServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new projectserviceModule.v2.ProjectServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.projectServiceStub, undefined); - await client.initialize(); - assert(client.projectServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.projectServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.projectServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new projectserviceModule.v2.ProjectServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new projectserviceModule.v2.ProjectServiceClient({ - 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); - }); - }); - - describe('getServiceAccount', () => { - it('invokes getServiceAccount without error', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetServiceAccountRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountResponse() - ); - client.innerApiCalls.getServiceAccount = stubSimpleCall(expectedResponse); - const [response] = await client.getServiceAccount(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceAccount without error using callback', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetServiceAccountRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountResponse() - ); - client.innerApiCalls.getServiceAccount = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getServiceAccount( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IGetServiceAccountResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceAccount with error', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetServiceAccountRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getServiceAccount = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getServiceAccount(request), expectedError); - const actualRequest = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceAccount as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceAccount with closed client', async () => { - const client = new projectserviceModule.v2.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetServiceAccountRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetServiceAccountRequest', ['projectId']); - request.projectId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getServiceAccount(request), expectedError); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_routine_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_routine_service_v2.ts.baseline deleted file mode 100644 index 20fc2d9d3f87..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_routine_service_v2.ts.baseline +++ /dev/null @@ -1,1118 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as routineserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.RoutineServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new routineserviceModule.v2.RoutineServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new routineserviceModule.v2.RoutineServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = routineserviceModule.v2.RoutineServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = routineserviceModule.v2.RoutineServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new routineserviceModule.v2.RoutineServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new routineserviceModule.v2.RoutineServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new routineserviceModule.v2.RoutineServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new routineserviceModule.v2.RoutineServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new routineserviceModule.v2.RoutineServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = routineserviceModule.v2.RoutineServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new routineserviceModule.v2.RoutineServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.routineServiceStub, undefined); - await client.initialize(); - assert(client.routineServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.routineServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.routineServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new routineserviceModule.v2.RoutineServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new routineserviceModule.v2.RoutineServiceClient({ - 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); - }); - }); - - describe('getRoutine', () => { - it('invokes getRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.getRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.getRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.getRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getRoutine( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getRoutine(request), expectedError); - const actualRequest = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getRoutine(request), expectedError); - }); - }); - - describe('insertRoutine', () => { - it('invokes insertRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.insertRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.insertRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.insertRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insertRoutine( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insertRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insertRoutine(request), expectedError); - const actualRequest = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insertRoutine(request), expectedError); - }); - }); - - describe('updateRoutine', () => { - it('invokes updateRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.updateRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.updateRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.updateRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateRoutine( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateRoutine(request), expectedError); - const actualRequest = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateRoutine(request), expectedError); - }); - }); - - describe('patchRoutine', () => { - it('invokes patchRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchRoutineRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.patchRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.patchRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes patchRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchRoutineRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Routine() - ); - client.innerApiCalls.patchRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patchRoutine( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes patchRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchRoutineRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.patchRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patchRoutine(request), expectedError); - }); - - it('invokes patchRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.PatchRoutineRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patchRoutine(request), expectedError); - }); - }); - - describe('deleteRoutine', () => { - it('invokes deleteRoutine without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoutine = stubSimpleCall(expectedResponse); - const [response] = await client.deleteRoutine(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoutine without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoutine = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteRoutine( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoutine with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&routine_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteRoutine = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteRoutine(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoutine as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoutine with closed client', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteRoutineRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteRoutineRequest', ['routineId']); - request.routineId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteRoutine(request), expectedError); - }); - }); - - describe('listRoutines', () => { - it('invokes listRoutines without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - ]; - client.innerApiCalls.listRoutines = stubSimpleCall(expectedResponse); - const [response] = await client.listRoutines(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRoutines without error using callback', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - ]; - client.innerApiCalls.listRoutines = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listRoutines( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRoutine[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRoutines with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listRoutines = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listRoutines(request), expectedError); - const actualRequest = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRoutines as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRoutinesStream without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - ]; - client.descriptors.page.listRoutines.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listRoutinesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.Routine[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.Routine) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listRoutines.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRoutines, request)); - assert( - (client.descriptors.page.listRoutines.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listRoutinesStream with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listRoutines.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listRoutinesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.Routine[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.Routine) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listRoutines.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRoutines, request)); - assert( - (client.descriptors.page.listRoutines.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listRoutines without error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.Routine()), - ]; - client.descriptors.page.listRoutines.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IRoutine[] = []; - const iterable = client.listRoutinesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRoutines.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listRoutines.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listRoutines with error', async () => { - const client = new routineserviceModule.v2.RoutineServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRoutinesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRoutinesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listRoutines.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listRoutinesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IRoutine[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRoutines.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listRoutines.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_row_access_policy_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_row_access_policy_service_v2.ts.baseline deleted file mode 100644 index a6bc8df9a403..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_row_access_policy_service_v2.ts.baseline +++ /dev/null @@ -1,548 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as rowaccesspolicyserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.RowAccessPolicyServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.rowAccessPolicyServiceStub, undefined); - await client.initialize(); - assert(client.rowAccessPolicyServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.rowAccessPolicyServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.rowAccessPolicyServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - 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); - }); - }); - - describe('listRowAccessPolicies', () => { - it('invokes listRowAccessPolicies without error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - ]; - client.innerApiCalls.listRowAccessPolicies = stubSimpleCall(expectedResponse); - const [response] = await client.listRowAccessPolicies(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRowAccessPolicies without error using callback', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - ]; - client.innerApiCalls.listRowAccessPolicies = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listRowAccessPolicies( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IRowAccessPolicy[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRowAccessPolicies with error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listRowAccessPolicies = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listRowAccessPolicies(request), expectedError); - const actualRequest = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listRowAccessPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listRowAccessPoliciesStream without error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - ]; - client.descriptors.page.listRowAccessPolicies.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listRowAccessPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.RowAccessPolicy[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.RowAccessPolicy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listRowAccessPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRowAccessPolicies, request)); - assert( - (client.descriptors.page.listRowAccessPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listRowAccessPoliciesStream with error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listRowAccessPolicies.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listRowAccessPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.RowAccessPolicy[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.RowAccessPolicy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listRowAccessPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRowAccessPolicies, request)); - assert( - (client.descriptors.page.listRowAccessPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listRowAccessPolicies without error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.RowAccessPolicy()), - ]; - client.descriptors.page.listRowAccessPolicies.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IRowAccessPolicy[] = []; - const iterable = client.listRowAccessPoliciesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRowAccessPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listRowAccessPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listRowAccessPolicies with error', async () => { - const client = new rowaccesspolicyserviceModule.v2.RowAccessPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListRowAccessPoliciesRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listRowAccessPolicies.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listRowAccessPoliciesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IRowAccessPolicy[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRowAccessPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listRowAccessPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_table_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_table_service_v2.ts.baseline deleted file mode 100644 index 1a1268a6e03e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/test/gapic_table_service_v2.ts.baseline +++ /dev/null @@ -1,1175 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as tableserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.TableServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new tableserviceModule.v2.TableServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new tableserviceModule.v2.TableServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = tableserviceModule.v2.TableServiceClient.servicePath; - assert.strictEqual(servicePath, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = tableserviceModule.v2.TableServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'bigquery.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new tableserviceModule.v2.TableServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new tableserviceModule.v2.TableServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new tableserviceModule.v2.TableServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new tableserviceModule.v2.TableServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'bigquery.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new tableserviceModule.v2.TableServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = tableserviceModule.v2.TableServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new tableserviceModule.v2.TableServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new tableserviceModule.v2.TableServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.tableServiceStub, undefined); - await client.initialize(); - assert(client.tableServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.tableServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.tableServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new tableserviceModule.v2.TableServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new tableserviceModule.v2.TableServiceClient({ - 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); - }); - }); - - describe('getTable', () => { - it('invokes getTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.getTable = stubSimpleCall(expectedResponse); - const [response] = await client.getTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.getTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getTable( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.ITable|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getTable(request), expectedError); - const actualRequest = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.GetTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.GetTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getTable(request), expectedError); - }); - }); - - describe('insertTable', () => { - it('invokes insertTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.insertTable = stubSimpleCall(expectedResponse); - const [response] = await client.insertTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.insertTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insertTable( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.ITable|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insertTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insertTable(request), expectedError); - const actualRequest = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insertTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insertTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.InsertTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.InsertTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insertTable(request), expectedError); - }); - }); - - describe('patchTable', () => { - it('invokes patchTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.patchTable = stubSimpleCall(expectedResponse); - const [response] = await client.patchTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.patchTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.patchTable( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.ITable|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.patchTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.patchTable(request), expectedError); - const actualRequest = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.patchTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes patchTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.patchTable(request), expectedError); - }); - }); - - describe('updateTable', () => { - it('invokes updateTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.updateTable = stubSimpleCall(expectedResponse); - const [response] = await client.updateTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.bigquery.v2.Table() - ); - client.innerApiCalls.updateTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateTable( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.ITable|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateTable(request), expectedError); - const actualRequest = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.UpdateOrPatchTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.UpdateOrPatchTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateTable(request), expectedError); - }); - }); - - describe('deleteTable', () => { - it('invokes deleteTable without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTable = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTable(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTable without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTable = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTable( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTable with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }&table_id=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTable = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTable(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTable as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTable with closed client', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.DeleteTableRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['datasetId']); - request.datasetId = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.bigquery.v2.DeleteTableRequest', ['tableId']); - request.tableId = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteTable(request), expectedError); - }); - }); - - describe('listTables', () => { - it('invokes listTables without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - ]; - client.innerApiCalls.listTables = stubSimpleCall(expectedResponse); - const [response] = await client.listTables(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTables without error using callback', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - ]; - client.innerApiCalls.listTables = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTables( - request, - (err?: Error|null, result?: protos.google.cloud.bigquery.v2.IListFormatTable[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTables with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTables = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTables(request), expectedError); - const actualRequest = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTables as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTablesStream without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - ]; - client.descriptors.page.listTables.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTablesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatTable[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatTable) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTables.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTables, request)); - assert( - (client.descriptors.page.listTables.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTablesStream with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTables.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTablesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.bigquery.v2.ListFormatTable[] = []; - stream.on('data', (response: protos.google.cloud.bigquery.v2.ListFormatTable) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTables.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTables, request)); - assert( - (client.descriptors.page.listTables.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTables without error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - generateSampleMessage(new protos.google.cloud.bigquery.v2.ListFormatTable()), - ]; - client.descriptors.page.listTables.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.bigquery.v2.IListFormatTable[] = []; - const iterable = client.listTablesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTables.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTables.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTables with error', async () => { - const client = new tableserviceModule.v2.TableServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.bigquery.v2.ListTablesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['projectId']); - request.projectId = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.bigquery.v2.ListTablesRequest', ['datasetId']); - request.datasetId = defaultValue2; - const expectedHeaderRequestParams = `project_id=${defaultValue1 ?? '' }&dataset_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTables.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTablesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.bigquery.v2.IListFormatTable[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTables.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTables.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/bigquery-v2/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/bigquery-v2/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/compute-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/compute-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index dc40b7f7a61f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const compute = require('@google-cloud/compute'); - -function main() { - const addressesClient = new compute.AddressesClient(); - const regionOperationsClient = new compute.RegionOperationsClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 578b143c5e0e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as compute from '@google-cloud/compute'; - -function main() { - const addressesClient = new compute.AddressesClient(); - const regionOperationsClient = new compute.RegionOperationsClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 8f000a23986d..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,39 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {AddressesClient, RegionOperationsClient} from '@google-cloud/compute'; - -// check that the client class type name can be used -function doStuffWithAddressesClient(client: AddressesClient) { - client.close(); -} -function doStuffWithRegionOperationsClient(client: RegionOperationsClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const addressesClient = new AddressesClient(); - doStuffWithAddressesClient(addressesClient); - // check that the client instance can be created - const regionOperationsClient = new RegionOperationsClient(); - doStuffWithRegionOperationsClient(regionOperationsClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/test/gapic_addresses_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/test/gapic_addresses_v1.ts.baseline deleted file mode 100644 index c09f37884264..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/test/gapic_addresses_v1.ts.baseline +++ /dev/null @@ -1,871 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it, beforeEach, afterEach} from 'mocha'; -import * as addressesModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {GoogleAuth, protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.AddressesClient', () => { - let googleAuth: GoogleAuth; - beforeEach(() => { - googleAuth = { - getClient: sinon.stub().resolves({ - getRequestHeaders: sinon.stub().resolves({Authorization: 'Bearer SOME_TOKEN'}), - }) - } as unknown as GoogleAuth; - }); - afterEach(() => { - sinon.restore(); - }); - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new addressesModule.v1.AddressesClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'compute.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new addressesModule.v1.AddressesClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = addressesModule.v1.AddressesClient.servicePath; - assert.strictEqual(servicePath, 'compute.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = addressesModule.v1.AddressesClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'compute.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new addressesModule.v1.AddressesClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new addressesModule.v1.AddressesClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new addressesModule.v1.AddressesClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new addressesModule.v1.AddressesClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new addressesModule.v1.AddressesClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = addressesModule.v1.AddressesClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new addressesModule.v1.AddressesClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new addressesModule.v1.AddressesClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - assert.strictEqual(client.addressesStub, undefined); - await client.initialize(); - assert(client.addressesStub); - }); - - it('has close method for the initialized client', done => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.addressesStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - assert.strictEqual(client.addressesStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - 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); - }); - }); - - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.DeleteAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['address']); - request.address = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&address=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response.latestResponse, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete without error using callback', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.DeleteAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['address']); - request.address = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&address=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.DeleteAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['address']); - request.address = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&address=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with closed client', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.DeleteAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['address']); - request.address = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); - }); - - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.InsertAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response.latestResponse, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert without error using callback', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.InsertAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.InsertAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with closed client', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.InsertAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['region']); - request.region = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); - }); - - describe('aggregatedList', () => { - - it('uses async iteration with aggregatedList without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.AggregatedListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.AggregatedListAddressesRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = [ - ['tuple_key_1', generateSampleMessage(new protos.google.cloud.compute.v1.AddressesScopedList())], - ['tuple_key_2', generateSampleMessage(new protos.google.cloud.compute.v1.AddressesScopedList())], - ['tuple_key_3', generateSampleMessage(new protos.google.cloud.compute.v1.AddressesScopedList())], - ]; - client.descriptors.page.aggregatedList.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: Array<[string, protos.google.cloud.compute.v1.IAddressesScopedList]> = []; - const iterable = client.aggregatedListAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.aggregatedList.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.aggregatedList.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with aggregatedList with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.AggregatedListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.AggregatedListAddressesRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.aggregatedList.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.aggregatedListAsync(request); - await assert.rejects(async () => { - const responses: Array<[string, protos.google.cloud.compute.v1.IAddressesScopedList]> = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.aggregatedList.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.aggregatedList.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('list', () => { - it('invokes list without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - ]; - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list without error using callback', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - ]; - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IAddress[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listStream without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - ]; - client.descriptors.page.list.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.compute.v1.Address[] = []; - stream.on('data', (response: protos.google.cloud.compute.v1.Address) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.list.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.list, request)); - assert( - (client.descriptors.page.list.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listStream with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.list.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.compute.v1.Address[] = []; - stream.on('data', (response: protos.google.cloud.compute.v1.Address) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.list.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.list, request)); - assert( - (client.descriptors.page.list.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with list without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - ]; - client.descriptors.page.list.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.compute.v1.IAddress[] = []; - const iterable = client.listAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.list.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.list.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with list with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.list.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.compute.v1.IAddress[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.list.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.list.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/test/gapic_region_operations_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/test/gapic_region_operations_v1.ts.baseline deleted file mode 100644 index 71f489ff7e31..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/esm/test/gapic_region_operations_v1.ts.baseline +++ /dev/null @@ -1,498 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it, beforeEach, afterEach} from 'mocha'; -import * as regionoperationsModule from '../src/index.js'; - -import {GoogleAuth, protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1.RegionOperationsClient', () => { - let googleAuth: GoogleAuth; - beforeEach(() => { - googleAuth = { - getClient: sinon.stub().resolves({ - getRequestHeaders: sinon.stub().resolves({Authorization: 'Bearer SOME_TOKEN'}), - }) - } as unknown as GoogleAuth; - }); - afterEach(() => { - sinon.restore(); - }); - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'compute.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = regionoperationsModule.v1.RegionOperationsClient.servicePath; - assert.strictEqual(servicePath, 'compute.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = regionoperationsModule.v1.RegionOperationsClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'compute.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new regionoperationsModule.v1.RegionOperationsClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new regionoperationsModule.v1.RegionOperationsClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new regionoperationsModule.v1.RegionOperationsClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = regionoperationsModule.v1.RegionOperationsClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - assert.strictEqual(client.regionOperationsStub, undefined); - await client.initialize(); - assert(client.regionOperationsStub); - }); - - it('has close method for the initialized client', done => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.regionOperationsStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - assert.strictEqual(client.regionOperationsStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - 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); - }); - }); - - describe('get', () => { - it('invokes get without error', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.GetRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get without error using callback', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.GetRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with error', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.GetRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with closed client', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.GetRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); - }); - - describe('wait', () => { - it('invokes wait without error', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.WaitRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.wait = stubSimpleCall(expectedResponse); - const [response] = await client.wait(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes wait without error using callback', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.WaitRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.wait = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.wait( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes wait with error', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.WaitRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.wait(request), expectedError); - const actualRequest = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes wait with closed client', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.WaitRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.wait(request), expectedError); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/package.json b/core/generator/gapic-generator-typescript/baselines/compute-esm/package.json index 574539631ffa..b435629f9f27 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/compute-esm/package.json @@ -61,12 +61,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -81,21 +75,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/compute-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/compute-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/compute-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/compute-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/compute/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/compute/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/compute/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/compute/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/compute/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/compute/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/compute/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/compute/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/compute/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/compute/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/compute/package.json b/core/generator/gapic-generator-typescript/baselines/compute/package.json index 341a8d6bb41f..d5a459261573 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute/package.json +++ b/core/generator/gapic-generator-typescript/baselines/compute/package.json @@ -31,27 +31,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/compute/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/compute/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 9fe84b556875..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const compute = require('@google-cloud/compute'); - -function main() { - const addressesClient = new compute.AddressesClient(); - const regionOperationsClient = new compute.RegionOperationsClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/compute/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/compute/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 33f6383ebf4c..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {AddressesClient, RegionOperationsClient} from '@google-cloud/compute'; - -// check that the client class type name can be used -function doStuffWithAddressesClient(client: AddressesClient) { - client.close(); -} -function doStuffWithRegionOperationsClient(client: RegionOperationsClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const addressesClient = new AddressesClient(); - doStuffWithAddressesClient(addressesClient); - // check that the client instance can be created - const regionOperationsClient = new RegionOperationsClient(); - doStuffWithRegionOperationsClient(regionOperationsClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/compute/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/compute/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/compute/test/gapic_addresses_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/compute/test/gapic_addresses_v1.ts.baseline deleted file mode 100644 index 730191a98310..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute/test/gapic_addresses_v1.ts.baseline +++ /dev/null @@ -1,862 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it, beforeEach, afterEach} from 'mocha'; -import * as addressesModule from '../src'; - -import {PassThrough} from 'stream'; - -import {GoogleAuth, protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.AddressesClient', () => { - let googleAuth: GoogleAuth; - beforeEach(() => { - googleAuth = { - getClient: sinon.stub().resolves({ - getRequestHeaders: sinon.stub().resolves({Authorization: 'Bearer SOME_TOKEN'}), - }) - } as unknown as GoogleAuth; - }); - afterEach(() => { - sinon.restore(); - }); - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new addressesModule.v1.AddressesClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'compute.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new addressesModule.v1.AddressesClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = addressesModule.v1.AddressesClient.servicePath; - assert.strictEqual(servicePath, 'compute.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = addressesModule.v1.AddressesClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'compute.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new addressesModule.v1.AddressesClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new addressesModule.v1.AddressesClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new addressesModule.v1.AddressesClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new addressesModule.v1.AddressesClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new addressesModule.v1.AddressesClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = addressesModule.v1.AddressesClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new addressesModule.v1.AddressesClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new addressesModule.v1.AddressesClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - assert.strictEqual(client.addressesStub, undefined); - await client.initialize(); - assert(client.addressesStub); - }); - - it('has close method for the initialized client', done => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.addressesStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - assert.strictEqual(client.addressesStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - 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); - }); - }); - - describe('delete', () => { - it('invokes delete without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.DeleteAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['address']); - request.address = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&address=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCall(expectedResponse); - const [response] = await client.delete(request); - assert.deepStrictEqual(response.latestResponse, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete without error using callback', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.DeleteAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['address']); - request.address = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&address=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.delete = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.delete( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.DeleteAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['address']); - request.address = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&address=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.delete = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.delete(request), expectedError); - const actualRequest = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.delete as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes delete with closed client', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.DeleteAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.DeleteAddressRequest', ['address']); - request.address = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.delete(request), expectedError); - }); - }); - - describe('insert', () => { - it('invokes insert without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.InsertAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCall(expectedResponse); - const [response] = await client.insert(request); - assert.deepStrictEqual(response.latestResponse, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert without error using callback', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.InsertAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.insert = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.insert( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.InsertAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.insert = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.insert(request), expectedError); - const actualRequest = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.insert as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes insert with closed client', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.InsertAddressRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.InsertAddressRequest', ['region']); - request.region = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.insert(request), expectedError); - }); - }); - - describe('aggregatedList', () => { - - it('uses async iteration with aggregatedList without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.AggregatedListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.AggregatedListAddressesRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = [ - ['tuple_key_1', generateSampleMessage(new protos.google.cloud.compute.v1.AddressesScopedList())], - ['tuple_key_2', generateSampleMessage(new protos.google.cloud.compute.v1.AddressesScopedList())], - ['tuple_key_3', generateSampleMessage(new protos.google.cloud.compute.v1.AddressesScopedList())], - ]; - client.descriptors.page.aggregatedList.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: Array<[string, protos.google.cloud.compute.v1.IAddressesScopedList]> = []; - const iterable = client.aggregatedListAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.aggregatedList.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.aggregatedList.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with aggregatedList with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.AggregatedListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.AggregatedListAddressesRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.aggregatedList.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.aggregatedListAsync(request); - await assert.rejects(async () => { - const responses: Array<[string, protos.google.cloud.compute.v1.IAddressesScopedList]> = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.aggregatedList.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.aggregatedList.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('list', () => { - it('invokes list without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - ]; - client.innerApiCalls.list = stubSimpleCall(expectedResponse); - const [response] = await client.list(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list without error using callback', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - ]; - client.innerApiCalls.list = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.list( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IAddress[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes list with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.list = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.list(request), expectedError); - const actualRequest = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.list as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listStream without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - ]; - client.descriptors.page.list.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.compute.v1.Address[] = []; - stream.on('data', (response: protos.google.cloud.compute.v1.Address) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.list.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.list, request)); - assert( - (client.descriptors.page.list.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listStream with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.list.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.compute.v1.Address[] = []; - stream.on('data', (response: protos.google.cloud.compute.v1.Address) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.list.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.list, request)); - assert( - (client.descriptors.page.list.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with list without error', async () => { - const client = new addressesModule.v1.AddressesClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - generateSampleMessage(new protos.google.cloud.compute.v1.Address()), - ]; - client.descriptors.page.list.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.compute.v1.IAddress[] = []; - const iterable = client.listAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.list.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.list.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with list with error', async () => { - const client = new addressesModule.v1.AddressesClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.ListAddressesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.ListAddressesRequest', ['region']); - request.region = defaultValue2; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.list.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.compute.v1.IAddress[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.list.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.list.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/compute/test/gapic_region_operations_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/compute/test/gapic_region_operations_v1.ts.baseline deleted file mode 100644 index 1315afcae7c4..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/compute/test/gapic_region_operations_v1.ts.baseline +++ /dev/null @@ -1,489 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it, beforeEach, afterEach} from 'mocha'; -import * as regionoperationsModule from '../src'; - -import {GoogleAuth, protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1.RegionOperationsClient', () => { - let googleAuth: GoogleAuth; - beforeEach(() => { - googleAuth = { - getClient: sinon.stub().resolves({ - getRequestHeaders: sinon.stub().resolves({Authorization: 'Bearer SOME_TOKEN'}), - }) - } as unknown as GoogleAuth; - }); - afterEach(() => { - sinon.restore(); - }); - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'compute.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = regionoperationsModule.v1.RegionOperationsClient.servicePath; - assert.strictEqual(servicePath, 'compute.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = regionoperationsModule.v1.RegionOperationsClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'compute.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new regionoperationsModule.v1.RegionOperationsClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new regionoperationsModule.v1.RegionOperationsClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'compute.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new regionoperationsModule.v1.RegionOperationsClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = regionoperationsModule.v1.RegionOperationsClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - assert.strictEqual(client.regionOperationsStub, undefined); - await client.initialize(); - assert(client.regionOperationsStub); - }); - - it('has close method for the initialized client', done => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.regionOperationsStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - assert.strictEqual(client.regionOperationsStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - 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); - }); - }); - - describe('get', () => { - it('invokes get without error', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.GetRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.get = stubSimpleCall(expectedResponse); - const [response] = await client.get(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get without error using callback', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.GetRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.get = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.get( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with error', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.GetRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.get = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.get(request), expectedError); - const actualRequest = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.get as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes get with closed client', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.GetRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.GetRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.get(request), expectedError); - }); - }); - - describe('wait', () => { - it('invokes wait without error', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.WaitRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.wait = stubSimpleCall(expectedResponse); - const [response] = await client.wait(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes wait without error using callback', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.WaitRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.compute.v1.Operation() - ); - client.innerApiCalls.wait = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.wait( - request, - (err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes wait with error', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.WaitRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }®ion=${defaultValue2 ?? '' }&operation=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.wait(request), expectedError); - const actualRequest = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.wait as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes wait with closed client', async () => { - const client = new regionoperationsModule.v1.RegionOperationsClient({ - auth: googleAuth, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.compute.v1.WaitRegionOperationRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['project']); - request.project = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['region']); - request.region = defaultValue2; - const defaultValue3 = - getTypeDefaultValue('.google.cloud.compute.v1.WaitRegionOperationRequest', ['operation']); - request.operation = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.wait(request), expectedError); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/compute/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/compute/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/compute/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/compute/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index e76463f5052f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const deprecatedtest = require('deprecatedtest'); - -function main() { - const deprecatedServiceClient = new deprecatedtest.DeprecatedServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 5255b6528d8a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as deprecatedtest from 'deprecatedtest'; - -function main() { - const deprecatedServiceClient = new deprecatedtest.DeprecatedServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 8ba7f01cacbd..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {DeprecatedServiceClient} from 'deprecatedtest'; - -// check that the client class type name can be used -function doStuffWithDeprecatedServiceClient(client: DeprecatedServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const deprecatedServiceClient = new DeprecatedServiceClient(); - doStuffWithDeprecatedServiceClient(deprecatedServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/package.json b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/package.json index 843f1661d115..efc43f759c8d 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/package.json b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/package.json index 88c1982c292e..0ce668506a10 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/package.json +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 062e9f68e68d..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const deprecatedtest = require('deprecatedtest'); - -function main() { - const deprecatedServiceClient = new deprecatedtest.DeprecatedServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 4327167deaf7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {DeprecatedServiceClient} from 'deprecatedtest'; - -// check that the client class type name can be used -function doStuffWithDeprecatedServiceClient(client: DeprecatedServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const deprecatedServiceClient = new DeprecatedServiceClient(); - doStuffWithDeprecatedServiceClient(deprecatedServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/deprecatedtest/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/deprecatedtest/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_compliance_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_compliance_v1beta1.ts.baseline deleted file mode 100644 index 7403c5712d59..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_compliance_v1beta1.ts.baseline +++ /dev/null @@ -1,1568 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as complianceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1beta1.ComplianceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = complianceModule.v1beta1.ComplianceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = complianceModule.v1beta1.ComplianceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new complianceModule.v1beta1.ComplianceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = complianceModule.v1beta1.ComplianceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.complianceStub, undefined); - await client.initialize(); - assert(client.complianceStub); - }); - - it('has close method for the initialized client', done => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.complianceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.complianceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new complianceModule.v1beta1.ComplianceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new complianceModule.v1beta1.ComplianceClient({ - 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); - }); - }); - - describe('repeatDataBody', () => { - it('invokes repeatDataBody without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBody = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBody(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBody without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBody = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBody( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBody with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBody = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBody(request), expectedError); - }); - - it('invokes repeatDataBody with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBody(request), expectedError); - }); - }); - - describe('repeatDataBodyInfo', () => { - it('invokes repeatDataBodyInfo without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyInfo(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyInfo without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyInfo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyInfo with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyInfo(request), expectedError); - }); - - it('invokes repeatDataBodyInfo with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyInfo(request), expectedError); - }); - }); - - describe('repeatDataQuery', () => { - it('invokes repeatDataQuery without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataQuery = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataQuery(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataQuery without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataQuery = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataQuery( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataQuery with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataQuery = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataQuery(request), expectedError); - }); - - it('invokes repeatDataQuery with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataQuery(request), expectedError); - }); - }); - - describe('repeatDataSimplePath', () => { - it('invokes repeatDataSimplePath without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataSimplePath(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataSimplePath( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataSimplePath(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataSimplePath(request), expectedError); - }); - }); - - describe('repeatDataPathResource', () => { - it('invokes repeatDataPathResource without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathResource = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataPathResource(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathResource = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataPathResource( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataPathResource = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataPathResource(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataPathResource(request), expectedError); - }); - }); - - describe('repeatDataPathTrailingResource', () => { - it('invokes repeatDataPathTrailingResource without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataPathTrailingResource(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataPathTrailingResource( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataPathTrailingResource(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataPathTrailingResource(request), expectedError); - }); - }); - - describe('repeatDataBodyPut', () => { - it('invokes repeatDataBodyPut without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyPut(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPut without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyPut( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPut with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyPut(request), expectedError); - }); - - it('invokes repeatDataBodyPut with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyPut(request), expectedError); - }); - }); - - describe('repeatDataBodyPatch', () => { - it('invokes repeatDataBodyPatch without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyPatch(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPatch without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyPatch( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPatch with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyPatch(request), expectedError); - }); - - it('invokes repeatDataBodyPatch with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyPatch(request), expectedError); - }); - }); - - describe('getEnum', () => { - it('invokes getEnum without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.getEnum = stubSimpleCall(expectedResponse); - const [response] = await client.getEnum(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getEnum without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.getEnum = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getEnum( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEnumResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getEnum with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.getEnum = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getEnum(request), expectedError); - }); - - it('invokes getEnum with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getEnum(request), expectedError); - }); - }); - - describe('verifyEnum', () => { - it('invokes verifyEnum without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.verifyEnum = stubSimpleCall(expectedResponse); - const [response] = await client.verifyEnum(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes verifyEnum without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.verifyEnum = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyEnum( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEnumResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes verifyEnum with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.verifyEnum = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyEnum(request), expectedError); - }); - - it('invokes verifyEnum with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyEnum(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_echo_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_echo_v1beta1.ts.baseline deleted file mode 100644 index 20d0e7f6fb07..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_echo_v1beta1.ts.baseline +++ /dev/null @@ -1,1537 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as echoModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.EchoClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new echoModule.v1beta1.EchoClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new echoModule.v1beta1.EchoClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = echoModule.v1beta1.EchoClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = echoModule.v1beta1.EchoClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new echoModule.v1beta1.EchoClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = echoModule.v1beta1.EchoClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new echoModule.v1beta1.EchoClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new echoModule.v1beta1.EchoClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - await client.initialize(); - assert(client.echoStub); - }); - - it('has close method for the initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.echoStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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); - }); - }); - - describe('echo', () => { - it('invokes echo without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCall(expectedResponse); - const [response] = await client.echo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echo(request), expectedError); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echo(request), expectedError); - }); - }); - - describe('echoErrorDetails', () => { - it('invokes echoErrorDetails without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(expectedResponse); - const [response] = await client.echoErrorDetails(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echoErrorDetails( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoErrorDetailsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - - it('invokes echoErrorDetails with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - }); - - describe('pagedExpandLegacy', () => { - it('invokes pagedExpandLegacy without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpandLegacy(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpandLegacy( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IPagedExpandResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - - it('invokes pagedExpandLegacy with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - }); - - describe('block', () => { - it('invokes block without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCall(expectedResponse); - const [response] = await client.block(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.block( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlockResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.block = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.block(request), expectedError); - }); - - it('invokes block with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.block(request), expectedError); - }); - }); - - describe('wait', () => { - it('invokes wait without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCall(expectedResponse); - const [operation] = await client.wait(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.wait( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait with call error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.wait(request), expectedError); - }); - - it('invokes wait with LRO error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.wait(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkWaitProgress without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkWaitProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkWaitProgress with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkWaitProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('expand', () => { - it('invokes expand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand without error and gaxServerStreamingRetries enabled', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.expand = stubServerStreamingCall(undefined, expectedError); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - - it('invokes expand with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.expand(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new echoModule.v1beta1.EchoClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('chat', () => { - it('invokes chat without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.chat = stubBidiStreamingCall(expectedResponse); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes chat with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.chat = stubBidiStreamingCall(undefined, expectedError); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('collect', () => { - it('invokes collect without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.collect = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes collect with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.collect = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('pagedExpand', () => { - it('invokes pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpand(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpand( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpand = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpand(request), expectedError); - }); - - it('invokes pagedExpandStream without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('invokes pagedExpandStream with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('uses async iteration with pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - const iterable = client.pagedExpandAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.pagedExpandAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_identity_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_identity_v1beta1.ts.baseline deleted file mode 100644 index 2da43f67b837..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_identity_v1beta1.ts.baseline +++ /dev/null @@ -1,1212 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as identityModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.IdentityClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new identityModule.v1beta1.IdentityClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new identityModule.v1beta1.IdentityClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = identityModule.v1beta1.IdentityClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = identityModule.v1beta1.IdentityClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new identityModule.v1beta1.IdentityClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = identityModule.v1beta1.IdentityClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new identityModule.v1beta1.IdentityClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new identityModule.v1beta1.IdentityClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.identityStub, undefined); - await client.initialize(); - assert(client.identityStub); - }); - - it('has close method for the initialized client', done => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.identityStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.identityStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new identityModule.v1beta1.IdentityClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new identityModule.v1beta1.IdentityClient({ - 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); - }); - }); - - describe('createUser', () => { - it('invokes createUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.createUser = stubSimpleCall(expectedResponse); - const [response] = await client.createUser(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.createUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createUser(request), expectedError); - }); - - it('invokes createUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createUser(request), expectedError); - }); - }); - - describe('getUser', () => { - it('invokes getUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.getUser = stubSimpleCall(expectedResponse); - const [response] = await client.getUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.getUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getUser(request), expectedError); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getUser(request), expectedError); - }); - }); - - describe('updateUser', () => { - it('invokes updateUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.updateUser = stubSimpleCall(expectedResponse); - const [response] = await client.updateUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.updateUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateUser(request), expectedError); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateUser(request), expectedError); - }); - }); - - describe('deleteUser', () => { - it('invokes deleteUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUser = stubSimpleCall(expectedResponse); - const [response] = await client.deleteUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteUser( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteUser(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteUser(request), expectedError); - }); - }); - - describe('listUsers', () => { - it('invokes listUsers without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.innerApiCalls.listUsers = stubSimpleCall(expectedResponse); - const [response] = await client.listUsers(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUsers without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.innerApiCalls.listUsers = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUsers( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUsers with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listUsers = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listUsers(request), expectedError); - }); - - it('invokes listUsersStream without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.descriptors.page.listUsers.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listUsersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.User[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.User) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listUsers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUsers, request)); - }); - - it('invokes listUsersStream with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUsers.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listUsersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.User[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.User) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listUsers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUsers, request)); - }); - - it('uses async iteration with listUsers without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.descriptors.page.listUsers.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IUser[] = []; - const iterable = client.listUsersAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listUsers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listUsers with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUsers.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listUsersAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IUser[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listUsers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_messaging_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_messaging_v1beta1.ts.baseline deleted file mode 100644 index e65f87dfaf42..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_messaging_v1beta1.ts.baseline +++ /dev/null @@ -1,2364 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as messagingModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.MessagingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = messagingModule.v1beta1.MessagingClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = messagingModule.v1beta1.MessagingClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new messagingModule.v1beta1.MessagingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = messagingModule.v1beta1.MessagingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new messagingModule.v1beta1.MessagingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.messagingStub, undefined); - await client.initialize(); - assert(client.messagingStub); - }); - - it('has close method for the initialized client', done => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.messagingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.messagingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new messagingModule.v1beta1.MessagingClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new messagingModule.v1beta1.MessagingClient({ - 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); - }); - }); - - describe('createRoom', () => { - it('invokes createRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.createRoom = stubSimpleCall(expectedResponse); - const [response] = await client.createRoom(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.createRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createRoom(request), expectedError); - }); - - it('invokes createRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createRoom(request), expectedError); - }); - }); - - describe('getRoom', () => { - it('invokes getRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.getRoom = stubSimpleCall(expectedResponse); - const [response] = await client.getRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.getRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getRoom(request), expectedError); - }); - }); - - describe('updateRoom', () => { - it('invokes updateRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.updateRoom = stubSimpleCall(expectedResponse); - const [response] = await client.updateRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.updateRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateRoom(request), expectedError); - }); - }); - - describe('deleteRoom', () => { - it('invokes deleteRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoom = stubSimpleCall(expectedResponse); - const [response] = await client.deleteRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteRoom( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteRoom(request), expectedError); - }); - }); - - describe('createBlurb', () => { - it('invokes createBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.createBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.createBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.createBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createBlurb(request), expectedError); - }); - }); - - describe('getBlurb', () => { - it('invokes getBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.getBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.getBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.getBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBlurb(request), expectedError); - }); - }); - - describe('updateBlurb', () => { - it('invokes updateBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.updateBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.updateBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.updateBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateBlurb(request), expectedError); - }); - }); - - describe('deleteBlurb', () => { - it('invokes deleteBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBlurb( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteBlurb(request), expectedError); - }); - }); - - describe('searchBlurbs', () => { - it('invokes searchBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(expectedResponse); - const [operation] = await client.searchBlurbs(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.searchBlurbs = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.searchBlurbs( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs with call error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.searchBlurbs(request), expectedError); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs with LRO error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.searchBlurbs(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkSearchBlurbsProgress without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkSearchBlurbsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkSearchBlurbsProgress with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkSearchBlurbsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('streamBlurbs', () => { - it('invokes streamBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs without error and gaxServerStreamingRetries enabled', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(undefined, expectedError); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.streamBlurbs(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new messagingModule.v1beta1.MessagingClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('connect', () => { - it('invokes connect without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ConnectRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.connect = stubBidiStreamingCall(expectedResponse); - const stream = client.connect(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.connect as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes connect with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ConnectRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.connect = stubBidiStreamingCall(undefined, expectedError); - const stream = client.connect(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.connect as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('sendBlurbs', () => { - it('invokes sendBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SendBlurbsResponse() - ); - client.innerApiCalls.sendBlurbs = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.sendBlurbs( - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISendBlurbsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.sendBlurbs as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes sendBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.sendBlurbs = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.sendBlurbs( - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISendBlurbsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.sendBlurbs as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('listRooms', () => { - it('invokes listRooms without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.innerApiCalls.listRooms = stubSimpleCall(expectedResponse); - const [response] = await client.listRooms(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listRooms without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.innerApiCalls.listRooms = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listRooms( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listRooms with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listRooms = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listRooms(request), expectedError); - }); - - it('invokes listRoomsStream without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.descriptors.page.listRooms.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listRoomsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Room[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Room) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listRooms.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRooms, request)); - }); - - it('invokes listRoomsStream with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listRooms.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listRoomsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Room[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Room) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listRooms.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRooms, request)); - }); - - it('uses async iteration with listRooms without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.descriptors.page.listRooms.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IRoom[] = []; - const iterable = client.listRoomsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRooms.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listRooms with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listRooms.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listRoomsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IRoom[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRooms.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listBlurbs', () => { - it('invokes listBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.innerApiCalls.listBlurbs = stubSimpleCall(expectedResponse); - const [response] = await client.listBlurbs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbs without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.innerApiCalls.listBlurbs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBlurbs( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBlurbs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBlurbs(request), expectedError); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbsStream without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.descriptors.page.listBlurbs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listBlurbsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Blurb[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Blurb) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBlurbs, request)); - assert( - (client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listBlurbsStream with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBlurbs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listBlurbsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Blurb[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Blurb) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBlurbs, request)); - assert( - (client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.descriptors.page.listBlurbs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IBlurb[] = []; - const iterable = client.listBlurbsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBlurbs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBlurbsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IBlurb[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_sequence_service_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_sequence_service_v1beta1.ts.baseline deleted file mode 100644 index 6ad653d66ad9..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_sequence_service_v1beta1.ts.baseline +++ /dev/null @@ -1,878 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as sequenceserviceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1beta1.SequenceServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = sequenceserviceModule.v1beta1.SequenceServiceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sequenceserviceModule.v1beta1.SequenceServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sequenceserviceModule.v1beta1.SequenceServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = sequenceserviceModule.v1beta1.SequenceServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sequenceServiceStub, undefined); - await client.initialize(); - assert(client.sequenceServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sequenceServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sequenceServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - 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); - }); - }); - - describe('createSequence', () => { - it('invokes createSequence without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Sequence() - ); - client.innerApiCalls.createSequence = stubSimpleCall(expectedResponse); - const [response] = await client.createSequence(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSequence without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Sequence() - ); - client.innerApiCalls.createSequence = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSequence( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISequence|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSequence with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createSequence = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSequence(request), expectedError); - }); - - it('invokes createSequence with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSequence(request), expectedError); - }); - }); - - describe('getSequenceReport', () => { - it('invokes getSequenceReport without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SequenceReport() - ); - client.innerApiCalls.getSequenceReport = stubSimpleCall(expectedResponse); - const [response] = await client.getSequenceReport(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SequenceReport() - ); - client.innerApiCalls.getSequenceReport = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSequenceReport( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISequenceReport|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSequenceReport = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSequenceReport(request), expectedError); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSequenceReport(request), expectedError); - }); - }); - - describe('attemptSequence', () => { - it('invokes attemptSequence without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.attemptSequence = stubSimpleCall(expectedResponse); - const [response] = await client.attemptSequence(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.attemptSequence = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.attemptSequence( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.attemptSequence = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.attemptSequence(request), expectedError); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.attemptSequence(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_testing_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_testing_v1beta1.ts.baseline deleted file mode 100644 index f19fcdb3cbb3..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/esm/test/gapic_testing_v1beta1.ts.baseline +++ /dev/null @@ -1,1669 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as testingModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.TestingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new testingModule.v1beta1.TestingClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new testingModule.v1beta1.TestingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = testingModule.v1beta1.TestingClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = testingModule.v1beta1.TestingClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new testingModule.v1beta1.TestingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = testingModule.v1beta1.TestingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new testingModule.v1beta1.TestingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new testingModule.v1beta1.TestingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testingStub, undefined); - await client.initialize(); - assert(client.testingStub); - }); - - it('has close method for the initialized client', done => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.testingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testingModule.v1beta1.TestingClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testingModule.v1beta1.TestingClient({ - 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); - }); - }); - - describe('createSession', () => { - it('invokes createSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.createSession = stubSimpleCall(expectedResponse); - const [response] = await client.createSession(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.createSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSession(request), expectedError); - }); - - it('invokes createSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSession(request), expectedError); - }); - }); - - describe('getSession', () => { - it('invokes getSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.getSession = stubSimpleCall(expectedResponse); - const [response] = await client.getSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.getSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSession(request), expectedError); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSession(request), expectedError); - }); - }); - - describe('deleteSession', () => { - it('invokes deleteSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSession = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSession( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSession(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteSession(request), expectedError); - }); - }); - - describe('reportSession', () => { - it('invokes reportSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionResponse() - ); - client.innerApiCalls.reportSession = stubSimpleCall(expectedResponse); - const [response] = await client.reportSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionResponse() - ); - client.innerApiCalls.reportSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.reportSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IReportSessionResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.reportSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.reportSession(request), expectedError); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.reportSession(request), expectedError); - }); - }); - - describe('deleteTest', () => { - it('invokes deleteTest without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTest = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTest(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTest = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTest( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTest = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTest(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteTest(request), expectedError); - }); - }); - - describe('verifyTest', () => { - it('invokes verifyTest without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestResponse() - ); - client.innerApiCalls.verifyTest = stubSimpleCall(expectedResponse); - const [response] = await client.verifyTest(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestResponse() - ); - client.innerApiCalls.verifyTest = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyTest( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IVerifyTestResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.verifyTest = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyTest(request), expectedError); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyTest(request), expectedError); - }); - }); - - describe('listSessions', () => { - it('invokes listSessions without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.innerApiCalls.listSessions = stubSimpleCall(expectedResponse); - const [response] = await client.listSessions(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listSessions without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.innerApiCalls.listSessions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSessions( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listSessions with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listSessions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSessions(request), expectedError); - }); - - it('invokes listSessionsStream without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.descriptors.page.listSessions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSessionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Session[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Session) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listSessions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSessions, request)); - }); - - it('invokes listSessionsStream with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listSessions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSessionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Session[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Session) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSessions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSessions, request)); - }); - - it('uses async iteration with listSessions without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.descriptors.page.listSessions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.ISession[] = []; - const iterable = client.listSessionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSessions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listSessions with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listSessions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSessionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.ISession[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSessions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listTests', () => { - it('invokes listTests without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.innerApiCalls.listTests = stubSimpleCall(expectedResponse); - const [response] = await client.listTests(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTests without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.innerApiCalls.listTests = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTests( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ITest[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTests with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTests = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTests(request), expectedError); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTestsStream without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.descriptors.page.listTests.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTestsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Test[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Test) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTests, request)); - assert( - (client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTestsStream with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTests.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTestsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Test[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Test) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTests, request)); - assert( - (client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTests without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.descriptors.page.listTests.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.ITest[] = []; - const iterable = client.listTestsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTests with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTests.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTestsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.ITest[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/package.json b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/package.json index 6de66ad2bdaf..6df8dd8f0209 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/package.json @@ -65,12 +65,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -85,21 +79,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/package.json b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/package.json index e02a97d7b12a..d12cb40851b5 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/package.json +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/package.json @@ -35,27 +35,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_compliance_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_compliance_v1beta1.ts.baseline deleted file mode 100644 index 33c4db06519a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_compliance_v1beta1.ts.baseline +++ /dev/null @@ -1,1559 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as complianceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1beta1.ComplianceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = complianceModule.v1beta1.ComplianceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = complianceModule.v1beta1.ComplianceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new complianceModule.v1beta1.ComplianceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = complianceModule.v1beta1.ComplianceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.complianceStub, undefined); - await client.initialize(); - assert(client.complianceStub); - }); - - it('has close method for the initialized client', done => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.complianceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.complianceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new complianceModule.v1beta1.ComplianceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new complianceModule.v1beta1.ComplianceClient({ - 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); - }); - }); - - describe('repeatDataBody', () => { - it('invokes repeatDataBody without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBody = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBody(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBody without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBody = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBody( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBody with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBody = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBody(request), expectedError); - }); - - it('invokes repeatDataBody with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBody(request), expectedError); - }); - }); - - describe('repeatDataBodyInfo', () => { - it('invokes repeatDataBodyInfo without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyInfo(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyInfo without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyInfo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyInfo with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyInfo(request), expectedError); - }); - - it('invokes repeatDataBodyInfo with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyInfo(request), expectedError); - }); - }); - - describe('repeatDataQuery', () => { - it('invokes repeatDataQuery without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataQuery = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataQuery(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataQuery without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataQuery = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataQuery( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataQuery with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataQuery = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataQuery(request), expectedError); - }); - - it('invokes repeatDataQuery with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataQuery(request), expectedError); - }); - }); - - describe('repeatDataSimplePath', () => { - it('invokes repeatDataSimplePath without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataSimplePath(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataSimplePath( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataSimplePath(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataSimplePath(request), expectedError); - }); - }); - - describe('repeatDataPathResource', () => { - it('invokes repeatDataPathResource without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathResource = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataPathResource(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathResource = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataPathResource( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataPathResource = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataPathResource(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataPathResource(request), expectedError); - }); - }); - - describe('repeatDataPathTrailingResource', () => { - it('invokes repeatDataPathTrailingResource without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataPathTrailingResource(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataPathTrailingResource( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataPathTrailingResource(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataPathTrailingResource(request), expectedError); - }); - }); - - describe('repeatDataBodyPut', () => { - it('invokes repeatDataBodyPut without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyPut(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPut without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyPut( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPut with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyPut(request), expectedError); - }); - - it('invokes repeatDataBodyPut with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyPut(request), expectedError); - }); - }); - - describe('repeatDataBodyPatch', () => { - it('invokes repeatDataBodyPatch without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyPatch(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPatch without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyPatch( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPatch with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyPatch(request), expectedError); - }); - - it('invokes repeatDataBodyPatch with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyPatch(request), expectedError); - }); - }); - - describe('getEnum', () => { - it('invokes getEnum without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.getEnum = stubSimpleCall(expectedResponse); - const [response] = await client.getEnum(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getEnum without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.getEnum = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getEnum( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEnumResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getEnum with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.getEnum = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getEnum(request), expectedError); - }); - - it('invokes getEnum with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getEnum(request), expectedError); - }); - }); - - describe('verifyEnum', () => { - it('invokes verifyEnum without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.verifyEnum = stubSimpleCall(expectedResponse); - const [response] = await client.verifyEnum(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes verifyEnum without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.verifyEnum = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyEnum( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEnumResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes verifyEnum with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.verifyEnum = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyEnum(request), expectedError); - }); - - it('invokes verifyEnum with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyEnum(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_echo_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_echo_v1beta1.ts.baseline deleted file mode 100644 index 1f5a591bdcd3..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_echo_v1beta1.ts.baseline +++ /dev/null @@ -1,1529 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as echoModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.EchoClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new echoModule.v1beta1.EchoClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new echoModule.v1beta1.EchoClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = echoModule.v1beta1.EchoClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = echoModule.v1beta1.EchoClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new echoModule.v1beta1.EchoClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = echoModule.v1beta1.EchoClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new echoModule.v1beta1.EchoClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new echoModule.v1beta1.EchoClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - await client.initialize(); - assert(client.echoStub); - }); - - it('has close method for the initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.echoStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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); - }); - }); - - describe('echo', () => { - it('invokes echo without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCall(expectedResponse); - const [response] = await client.echo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echo(request), expectedError); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echo(request), expectedError); - }); - }); - - describe('echoErrorDetails', () => { - it('invokes echoErrorDetails without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(expectedResponse); - const [response] = await client.echoErrorDetails(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echoErrorDetails( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoErrorDetailsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - - it('invokes echoErrorDetails with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - }); - - describe('pagedExpandLegacy', () => { - it('invokes pagedExpandLegacy without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpandLegacy(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpandLegacy( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IPagedExpandResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - - it('invokes pagedExpandLegacy with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - }); - - describe('block', () => { - it('invokes block without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCall(expectedResponse); - const [response] = await client.block(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.block( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlockResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.block = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.block(request), expectedError); - }); - - it('invokes block with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.block(request), expectedError); - }); - }); - - describe('wait', () => { - it('invokes wait without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCall(expectedResponse); - const [operation] = await client.wait(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.wait( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait with call error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.wait(request), expectedError); - }); - - it('invokes wait with LRO error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.wait(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkWaitProgress without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkWaitProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkWaitProgress with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkWaitProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('expand', () => { - it('invokes expand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand without error and gaxServerStreamingRetries enabled', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.expand = stubServerStreamingCall(undefined, expectedError); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - - it('invokes expand with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.expand(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new echoModule.v1beta1.EchoClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('chat', () => { - it('invokes chat without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.chat = stubBidiStreamingCall(expectedResponse); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes chat with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.chat = stubBidiStreamingCall(undefined, expectedError); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('collect', () => { - it('invokes collect without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.collect = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes collect with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.collect = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('pagedExpand', () => { - it('invokes pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpand(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpand( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpand = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpand(request), expectedError); - }); - - it('invokes pagedExpandStream without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('invokes pagedExpandStream with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('uses async iteration with pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - const iterable = client.pagedExpandAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.pagedExpandAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_identity_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_identity_v1beta1.ts.baseline deleted file mode 100644 index b938f6196ed4..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_identity_v1beta1.ts.baseline +++ /dev/null @@ -1,1203 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as identityModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.IdentityClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new identityModule.v1beta1.IdentityClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new identityModule.v1beta1.IdentityClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = identityModule.v1beta1.IdentityClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = identityModule.v1beta1.IdentityClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new identityModule.v1beta1.IdentityClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = identityModule.v1beta1.IdentityClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new identityModule.v1beta1.IdentityClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new identityModule.v1beta1.IdentityClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.identityStub, undefined); - await client.initialize(); - assert(client.identityStub); - }); - - it('has close method for the initialized client', done => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.identityStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.identityStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new identityModule.v1beta1.IdentityClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new identityModule.v1beta1.IdentityClient({ - 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); - }); - }); - - describe('createUser', () => { - it('invokes createUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.createUser = stubSimpleCall(expectedResponse); - const [response] = await client.createUser(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.createUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createUser(request), expectedError); - }); - - it('invokes createUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createUser(request), expectedError); - }); - }); - - describe('getUser', () => { - it('invokes getUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.getUser = stubSimpleCall(expectedResponse); - const [response] = await client.getUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.getUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getUser(request), expectedError); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getUser(request), expectedError); - }); - }); - - describe('updateUser', () => { - it('invokes updateUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.updateUser = stubSimpleCall(expectedResponse); - const [response] = await client.updateUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.updateUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateUser(request), expectedError); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateUser(request), expectedError); - }); - }); - - describe('deleteUser', () => { - it('invokes deleteUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUser = stubSimpleCall(expectedResponse); - const [response] = await client.deleteUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteUser( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteUser(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteUser(request), expectedError); - }); - }); - - describe('listUsers', () => { - it('invokes listUsers without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.innerApiCalls.listUsers = stubSimpleCall(expectedResponse); - const [response] = await client.listUsers(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUsers without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.innerApiCalls.listUsers = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUsers( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUsers with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listUsers = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listUsers(request), expectedError); - }); - - it('invokes listUsersStream without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.descriptors.page.listUsers.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listUsersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.User[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.User) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listUsers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUsers, request)); - }); - - it('invokes listUsersStream with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUsers.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listUsersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.User[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.User) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listUsers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUsers, request)); - }); - - it('uses async iteration with listUsers without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.descriptors.page.listUsers.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IUser[] = []; - const iterable = client.listUsersAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listUsers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listUsers with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUsers.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listUsersAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IUser[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listUsers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_messaging_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_messaging_v1beta1.ts.baseline deleted file mode 100644 index d7b2ff9708e6..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_messaging_v1beta1.ts.baseline +++ /dev/null @@ -1,2356 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as messagingModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.MessagingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = messagingModule.v1beta1.MessagingClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = messagingModule.v1beta1.MessagingClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new messagingModule.v1beta1.MessagingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = messagingModule.v1beta1.MessagingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new messagingModule.v1beta1.MessagingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.messagingStub, undefined); - await client.initialize(); - assert(client.messagingStub); - }); - - it('has close method for the initialized client', done => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.messagingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.messagingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new messagingModule.v1beta1.MessagingClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new messagingModule.v1beta1.MessagingClient({ - 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); - }); - }); - - describe('createRoom', () => { - it('invokes createRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.createRoom = stubSimpleCall(expectedResponse); - const [response] = await client.createRoom(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.createRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createRoom(request), expectedError); - }); - - it('invokes createRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createRoom(request), expectedError); - }); - }); - - describe('getRoom', () => { - it('invokes getRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.getRoom = stubSimpleCall(expectedResponse); - const [response] = await client.getRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.getRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getRoom(request), expectedError); - }); - }); - - describe('updateRoom', () => { - it('invokes updateRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.updateRoom = stubSimpleCall(expectedResponse); - const [response] = await client.updateRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.updateRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateRoom(request), expectedError); - }); - }); - - describe('deleteRoom', () => { - it('invokes deleteRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoom = stubSimpleCall(expectedResponse); - const [response] = await client.deleteRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteRoom( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteRoom(request), expectedError); - }); - }); - - describe('createBlurb', () => { - it('invokes createBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.createBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.createBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.createBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createBlurb(request), expectedError); - }); - }); - - describe('getBlurb', () => { - it('invokes getBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.getBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.getBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.getBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBlurb(request), expectedError); - }); - }); - - describe('updateBlurb', () => { - it('invokes updateBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.updateBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.updateBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.updateBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateBlurb(request), expectedError); - }); - }); - - describe('deleteBlurb', () => { - it('invokes deleteBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBlurb( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteBlurb(request), expectedError); - }); - }); - - describe('searchBlurbs', () => { - it('invokes searchBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(expectedResponse); - const [operation] = await client.searchBlurbs(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.searchBlurbs = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.searchBlurbs( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs with call error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.searchBlurbs(request), expectedError); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs with LRO error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.searchBlurbs(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkSearchBlurbsProgress without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkSearchBlurbsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkSearchBlurbsProgress with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkSearchBlurbsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('streamBlurbs', () => { - it('invokes streamBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs without error and gaxServerStreamingRetries enabled', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(undefined, expectedError); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.streamBlurbs(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new messagingModule.v1beta1.MessagingClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('connect', () => { - it('invokes connect without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ConnectRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.connect = stubBidiStreamingCall(expectedResponse); - const stream = client.connect(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.connect as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes connect with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ConnectRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.connect = stubBidiStreamingCall(undefined, expectedError); - const stream = client.connect(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.connect as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('sendBlurbs', () => { - it('invokes sendBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SendBlurbsResponse() - ); - client.innerApiCalls.sendBlurbs = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.sendBlurbs( - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISendBlurbsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.sendBlurbs as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes sendBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.sendBlurbs = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.sendBlurbs( - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISendBlurbsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.sendBlurbs as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('listRooms', () => { - it('invokes listRooms without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.innerApiCalls.listRooms = stubSimpleCall(expectedResponse); - const [response] = await client.listRooms(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listRooms without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.innerApiCalls.listRooms = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listRooms( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listRooms with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listRooms = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listRooms(request), expectedError); - }); - - it('invokes listRoomsStream without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.descriptors.page.listRooms.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listRoomsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Room[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Room) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listRooms.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRooms, request)); - }); - - it('invokes listRoomsStream with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listRooms.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listRoomsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Room[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Room) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listRooms.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRooms, request)); - }); - - it('uses async iteration with listRooms without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.descriptors.page.listRooms.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IRoom[] = []; - const iterable = client.listRoomsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRooms.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listRooms with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listRooms.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listRoomsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IRoom[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRooms.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listBlurbs', () => { - it('invokes listBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.innerApiCalls.listBlurbs = stubSimpleCall(expectedResponse); - const [response] = await client.listBlurbs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbs without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.innerApiCalls.listBlurbs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBlurbs( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBlurbs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBlurbs(request), expectedError); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbsStream without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.descriptors.page.listBlurbs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listBlurbsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Blurb[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Blurb) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBlurbs, request)); - assert( - (client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listBlurbsStream with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBlurbs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listBlurbsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Blurb[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Blurb) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBlurbs, request)); - assert( - (client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.descriptors.page.listBlurbs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IBlurb[] = []; - const iterable = client.listBlurbsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBlurbs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBlurbsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IBlurb[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_sequence_service_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_sequence_service_v1beta1.ts.baseline deleted file mode 100644 index e772cf81a761..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_sequence_service_v1beta1.ts.baseline +++ /dev/null @@ -1,869 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as sequenceserviceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1beta1.SequenceServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = sequenceserviceModule.v1beta1.SequenceServiceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sequenceserviceModule.v1beta1.SequenceServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sequenceserviceModule.v1beta1.SequenceServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = sequenceserviceModule.v1beta1.SequenceServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sequenceServiceStub, undefined); - await client.initialize(); - assert(client.sequenceServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sequenceServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sequenceServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - 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); - }); - }); - - describe('createSequence', () => { - it('invokes createSequence without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Sequence() - ); - client.innerApiCalls.createSequence = stubSimpleCall(expectedResponse); - const [response] = await client.createSequence(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSequence without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Sequence() - ); - client.innerApiCalls.createSequence = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSequence( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISequence|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSequence with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createSequence = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSequence(request), expectedError); - }); - - it('invokes createSequence with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSequence(request), expectedError); - }); - }); - - describe('getSequenceReport', () => { - it('invokes getSequenceReport without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SequenceReport() - ); - client.innerApiCalls.getSequenceReport = stubSimpleCall(expectedResponse); - const [response] = await client.getSequenceReport(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SequenceReport() - ); - client.innerApiCalls.getSequenceReport = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSequenceReport( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISequenceReport|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSequenceReport = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSequenceReport(request), expectedError); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSequenceReport(request), expectedError); - }); - }); - - describe('attemptSequence', () => { - it('invokes attemptSequence without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.attemptSequence = stubSimpleCall(expectedResponse); - const [response] = await client.attemptSequence(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.attemptSequence = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.attemptSequence( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.attemptSequence = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.attemptSequence(request), expectedError); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.attemptSequence(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_testing_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_testing_v1beta1.ts.baseline deleted file mode 100644 index 55e55cff9e27..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/test/gapic_testing_v1beta1.ts.baseline +++ /dev/null @@ -1,1660 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as testingModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.TestingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new testingModule.v1beta1.TestingClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new testingModule.v1beta1.TestingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = testingModule.v1beta1.TestingClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = testingModule.v1beta1.TestingClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new testingModule.v1beta1.TestingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = testingModule.v1beta1.TestingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new testingModule.v1beta1.TestingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new testingModule.v1beta1.TestingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testingStub, undefined); - await client.initialize(); - assert(client.testingStub); - }); - - it('has close method for the initialized client', done => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.testingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testingModule.v1beta1.TestingClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testingModule.v1beta1.TestingClient({ - 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); - }); - }); - - describe('createSession', () => { - it('invokes createSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.createSession = stubSimpleCall(expectedResponse); - const [response] = await client.createSession(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.createSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSession(request), expectedError); - }); - - it('invokes createSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSession(request), expectedError); - }); - }); - - describe('getSession', () => { - it('invokes getSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.getSession = stubSimpleCall(expectedResponse); - const [response] = await client.getSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.getSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSession(request), expectedError); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSession(request), expectedError); - }); - }); - - describe('deleteSession', () => { - it('invokes deleteSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSession = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSession( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSession(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteSession(request), expectedError); - }); - }); - - describe('reportSession', () => { - it('invokes reportSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionResponse() - ); - client.innerApiCalls.reportSession = stubSimpleCall(expectedResponse); - const [response] = await client.reportSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionResponse() - ); - client.innerApiCalls.reportSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.reportSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IReportSessionResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.reportSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.reportSession(request), expectedError); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.reportSession(request), expectedError); - }); - }); - - describe('deleteTest', () => { - it('invokes deleteTest without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTest = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTest(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTest = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTest( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTest = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTest(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteTest(request), expectedError); - }); - }); - - describe('verifyTest', () => { - it('invokes verifyTest without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestResponse() - ); - client.innerApiCalls.verifyTest = stubSimpleCall(expectedResponse); - const [response] = await client.verifyTest(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestResponse() - ); - client.innerApiCalls.verifyTest = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyTest( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IVerifyTestResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.verifyTest = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyTest(request), expectedError); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyTest(request), expectedError); - }); - }); - - describe('listSessions', () => { - it('invokes listSessions without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.innerApiCalls.listSessions = stubSimpleCall(expectedResponse); - const [response] = await client.listSessions(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listSessions without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.innerApiCalls.listSessions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSessions( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listSessions with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listSessions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSessions(request), expectedError); - }); - - it('invokes listSessionsStream without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.descriptors.page.listSessions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSessionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Session[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Session) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listSessions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSessions, request)); - }); - - it('invokes listSessionsStream with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listSessions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSessionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Session[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Session) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSessions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSessions, request)); - }); - - it('uses async iteration with listSessions without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.descriptors.page.listSessions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.ISession[] = []; - const iterable = client.listSessionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSessions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listSessions with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listSessions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSessionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.ISession[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSessions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listTests', () => { - it('invokes listTests without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.innerApiCalls.listTests = stubSimpleCall(expectedResponse); - const [response] = await client.listTests(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTests without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.innerApiCalls.listTests = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTests( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ITest[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTests with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTests = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTests(request), expectedError); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTestsStream without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.descriptors.page.listTests.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTestsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Test[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Test) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTests, request)); - assert( - (client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTestsStream with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTests.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTestsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Test[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Test) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTests, request)); - assert( - (client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTests without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.descriptors.page.listTests.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.ITest[] = []; - const iterable = client.listTestsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTests with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTests.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTestsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.ITest[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/disable-packing-test/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/disable-packing-test/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/dlp-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/dlp-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index de4514cb0cee..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const dlp = require('dlp'); - -function main() { - const dlpServiceClient = new dlp.DlpServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 31844a3b61a1..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as dlp from 'dlp'; - -function main() { - const dlpServiceClient = new dlp.DlpServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index d83930c09280..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {DlpServiceClient} from 'dlp'; - -// check that the client class type name can be used -function doStuffWithDlpServiceClient(client: DlpServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const dlpServiceClient = new DlpServiceClient(); - doStuffWithDlpServiceClient(dlpServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/test/gapic_dlp_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/test/gapic_dlp_service_v2.ts.baseline deleted file mode 100644 index 3da7e9dfb6f2..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/esm/test/gapic_dlp_service_v2.ts.baseline +++ /dev/null @@ -1,4883 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as dlpserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.DlpServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new dlpserviceModule.v2.DlpServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'dlp.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new dlpserviceModule.v2.DlpServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = dlpserviceModule.v2.DlpServiceClient.servicePath; - assert.strictEqual(servicePath, 'dlp.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = dlpserviceModule.v2.DlpServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'dlp.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new dlpserviceModule.v2.DlpServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'dlp.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new dlpserviceModule.v2.DlpServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'dlp.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new dlpserviceModule.v2.DlpServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'dlp.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new dlpserviceModule.v2.DlpServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'dlp.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new dlpserviceModule.v2.DlpServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = dlpserviceModule.v2.DlpServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new dlpserviceModule.v2.DlpServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.dlpServiceStub, undefined); - await client.initialize(); - assert(client.dlpServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.dlpServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.dlpServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new dlpserviceModule.v2.DlpServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new dlpserviceModule.v2.DlpServiceClient({ - 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); - }); - }); - - describe('inspectContent', () => { - it('invokes inspectContent without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentResponse() - ); - client.innerApiCalls.inspectContent = stubSimpleCall(expectedResponse); - const [response] = await client.inspectContent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes inspectContent without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentResponse() - ); - client.innerApiCalls.inspectContent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.inspectContent( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectContentResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes inspectContent with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.inspectContent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.inspectContent(request), expectedError); - const actualRequest = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes inspectContent with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.inspectContent(request), expectedError); - }); - }); - - describe('redactImage', () => { - it('invokes redactImage without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageResponse() - ); - client.innerApiCalls.redactImage = stubSimpleCall(expectedResponse); - const [response] = await client.redactImage(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes redactImage without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageResponse() - ); - client.innerApiCalls.redactImage = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.redactImage( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IRedactImageResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes redactImage with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.redactImage = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.redactImage(request), expectedError); - const actualRequest = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes redactImage with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.redactImage(request), expectedError); - }); - }); - - describe('deidentifyContent', () => { - it('invokes deidentifyContent without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentResponse() - ); - client.innerApiCalls.deidentifyContent = stubSimpleCall(expectedResponse); - const [response] = await client.deidentifyContent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deidentifyContent without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentResponse() - ); - client.innerApiCalls.deidentifyContent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deidentifyContent( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyContentResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deidentifyContent with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deidentifyContent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deidentifyContent(request), expectedError); - const actualRequest = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deidentifyContent with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deidentifyContent(request), expectedError); - }); - }); - - describe('reidentifyContent', () => { - it('invokes reidentifyContent without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentResponse() - ); - client.innerApiCalls.reidentifyContent = stubSimpleCall(expectedResponse); - const [response] = await client.reidentifyContent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reidentifyContent without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentResponse() - ); - client.innerApiCalls.reidentifyContent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.reidentifyContent( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IReidentifyContentResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reidentifyContent with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.reidentifyContent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.reidentifyContent(request), expectedError); - const actualRequest = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reidentifyContent with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.reidentifyContent(request), expectedError); - }); - }); - - describe('listInfoTypes', () => { - it('invokes listInfoTypes without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInfoTypesRequest', ['locationId']); - request.locationId = defaultValue1; - const expectedHeaderRequestParams = `location_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesResponse() - ); - client.innerApiCalls.listInfoTypes = stubSimpleCall(expectedResponse); - const [response] = await client.listInfoTypes(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInfoTypes without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInfoTypesRequest', ['locationId']); - request.locationId = defaultValue1; - const expectedHeaderRequestParams = `location_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesResponse() - ); - client.innerApiCalls.listInfoTypes = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listInfoTypes( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IListInfoTypesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInfoTypes with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInfoTypesRequest', ['locationId']); - request.locationId = defaultValue1; - const expectedHeaderRequestParams = `location_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listInfoTypes = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listInfoTypes(request), expectedError); - const actualRequest = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInfoTypes with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInfoTypesRequest', ['locationId']); - request.locationId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listInfoTypes(request), expectedError); - }); - }); - - describe('createInspectTemplate', () => { - it('invokes createInspectTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.createInspectTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.createInspectTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInspectTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.createInspectTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createInspectTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInspectTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createInspectTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createInspectTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInspectTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createInspectTemplate(request), expectedError); - }); - }); - - describe('updateInspectTemplate', () => { - it('invokes updateInspectTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.updateInspectTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.updateInspectTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInspectTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.updateInspectTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateInspectTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInspectTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateInspectTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateInspectTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInspectTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateInspectTemplate(request), expectedError); - }); - }); - - describe('getInspectTemplate', () => { - it('invokes getInspectTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.getInspectTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.getInspectTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInspectTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.getInspectTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getInspectTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInspectTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getInspectTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getInspectTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInspectTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getInspectTemplate(request), expectedError); - }); - }); - - describe('deleteInspectTemplate', () => { - it('invokes deleteInspectTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteInspectTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.deleteInspectTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInspectTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteInspectTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteInspectTemplate( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInspectTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteInspectTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteInspectTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInspectTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteInspectTemplate(request), expectedError); - }); - }); - - describe('createDeidentifyTemplate', () => { - it('invokes createDeidentifyTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.createDeidentifyTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.createDeidentifyTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDeidentifyTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.createDeidentifyTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createDeidentifyTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDeidentifyTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createDeidentifyTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createDeidentifyTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDeidentifyTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createDeidentifyTemplate(request), expectedError); - }); - }); - - describe('updateDeidentifyTemplate', () => { - it('invokes updateDeidentifyTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.updateDeidentifyTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.updateDeidentifyTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDeidentifyTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.updateDeidentifyTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateDeidentifyTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDeidentifyTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateDeidentifyTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateDeidentifyTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDeidentifyTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateDeidentifyTemplate(request), expectedError); - }); - }); - - describe('getDeidentifyTemplate', () => { - it('invokes getDeidentifyTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.getDeidentifyTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.getDeidentifyTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDeidentifyTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.getDeidentifyTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDeidentifyTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDeidentifyTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDeidentifyTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDeidentifyTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDeidentifyTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDeidentifyTemplate(request), expectedError); - }); - }); - - describe('deleteDeidentifyTemplate', () => { - it('invokes deleteDeidentifyTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDeidentifyTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.deleteDeidentifyTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDeidentifyTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDeidentifyTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDeidentifyTemplate( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDeidentifyTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDeidentifyTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteDeidentifyTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDeidentifyTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteDeidentifyTemplate(request), expectedError); - }); - }); - - describe('createJobTrigger', () => { - it('invokes createJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.createJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.createJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.createJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createJobTrigger( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IJobTrigger|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createJobTrigger(request), expectedError); - }); - }); - - describe('updateJobTrigger', () => { - it('invokes updateJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.updateJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.updateJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.updateJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateJobTrigger( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IJobTrigger|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateJobTrigger(request), expectedError); - }); - }); - - describe('getJobTrigger', () => { - it('invokes getJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.getJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.getJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.getJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getJobTrigger( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IJobTrigger|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getJobTrigger(request), expectedError); - }); - }); - - describe('deleteJobTrigger', () => { - it('invokes deleteJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.deleteJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteJobTrigger( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteJobTrigger(request), expectedError); - }); - }); - - describe('activateJobTrigger', () => { - it('invokes activateJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ActivateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ActivateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.activateJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.activateJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes activateJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ActivateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ActivateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.activateJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.activateJobTrigger( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDlpJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes activateJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ActivateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ActivateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.activateJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.activateJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes activateJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ActivateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ActivateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.activateJobTrigger(request), expectedError); - }); - }); - - describe('createDlpJob', () => { - it('invokes createDlpJob without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.createDlpJob = stubSimpleCall(expectedResponse); - const [response] = await client.createDlpJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDlpJob without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.createDlpJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createDlpJob( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDlpJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDlpJob with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createDlpJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createDlpJob(request), expectedError); - const actualRequest = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDlpJob with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createDlpJob(request), expectedError); - }); - }); - - describe('getDlpJob', () => { - it('invokes getDlpJob without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.getDlpJob = stubSimpleCall(expectedResponse); - const [response] = await client.getDlpJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDlpJob without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.getDlpJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDlpJob( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDlpJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDlpJob with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDlpJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDlpJob(request), expectedError); - const actualRequest = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDlpJob with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDlpJob(request), expectedError); - }); - }); - - describe('deleteDlpJob', () => { - it('invokes deleteDlpJob without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDlpJob = stubSimpleCall(expectedResponse); - const [response] = await client.deleteDlpJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDlpJob without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDlpJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDlpJob( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDlpJob with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDlpJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteDlpJob(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDlpJob with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteDlpJob(request), expectedError); - }); - }); - - describe('cancelDlpJob', () => { - it('invokes cancelDlpJob without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CancelDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CancelDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.cancelDlpJob = stubSimpleCall(expectedResponse); - const [response] = await client.cancelDlpJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelDlpJob without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CancelDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CancelDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.cancelDlpJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.cancelDlpJob( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelDlpJob with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CancelDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CancelDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.cancelDlpJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.cancelDlpJob(request), expectedError); - const actualRequest = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelDlpJob with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CancelDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CancelDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.cancelDlpJob(request), expectedError); - }); - }); - - describe('createStoredInfoType', () => { - it('invokes createStoredInfoType without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.createStoredInfoType = stubSimpleCall(expectedResponse); - const [response] = await client.createStoredInfoType(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createStoredInfoType without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.createStoredInfoType = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createStoredInfoType( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IStoredInfoType|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createStoredInfoType with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createStoredInfoType = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createStoredInfoType(request), expectedError); - const actualRequest = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createStoredInfoType with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createStoredInfoType(request), expectedError); - }); - }); - - describe('updateStoredInfoType', () => { - it('invokes updateStoredInfoType without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.updateStoredInfoType = stubSimpleCall(expectedResponse); - const [response] = await client.updateStoredInfoType(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateStoredInfoType without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.updateStoredInfoType = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateStoredInfoType( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IStoredInfoType|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateStoredInfoType with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateStoredInfoType = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateStoredInfoType(request), expectedError); - const actualRequest = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateStoredInfoType with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateStoredInfoType(request), expectedError); - }); - }); - - describe('getStoredInfoType', () => { - it('invokes getStoredInfoType without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.getStoredInfoType = stubSimpleCall(expectedResponse); - const [response] = await client.getStoredInfoType(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getStoredInfoType without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.getStoredInfoType = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getStoredInfoType( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IStoredInfoType|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getStoredInfoType with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getStoredInfoType = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getStoredInfoType(request), expectedError); - const actualRequest = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getStoredInfoType with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getStoredInfoType(request), expectedError); - }); - }); - - describe('deleteStoredInfoType', () => { - it('invokes deleteStoredInfoType without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteStoredInfoType = stubSimpleCall(expectedResponse); - const [response] = await client.deleteStoredInfoType(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteStoredInfoType without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteStoredInfoType = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteStoredInfoType( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteStoredInfoType with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteStoredInfoType = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteStoredInfoType(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteStoredInfoType with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteStoredInfoType(request), expectedError); - }); - }); - - describe('listInspectTemplates', () => { - it('invokes listInspectTemplates without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - ]; - client.innerApiCalls.listInspectTemplates = stubSimpleCall(expectedResponse); - const [response] = await client.listInspectTemplates(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInspectTemplates without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - ]; - client.innerApiCalls.listInspectTemplates = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listInspectTemplates( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectTemplate[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInspectTemplates with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listInspectTemplates = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listInspectTemplates(request), expectedError); - const actualRequest = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInspectTemplatesStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - ]; - client.descriptors.page.listInspectTemplates.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listInspectTemplatesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.InspectTemplate[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.InspectTemplate) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listInspectTemplates.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listInspectTemplates, request)); - assert( - (client.descriptors.page.listInspectTemplates.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listInspectTemplatesStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listInspectTemplates.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listInspectTemplatesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.InspectTemplate[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.InspectTemplate) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listInspectTemplates.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listInspectTemplates, request)); - assert( - (client.descriptors.page.listInspectTemplates.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listInspectTemplates without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - ]; - client.descriptors.page.listInspectTemplates.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IInspectTemplate[] = []; - const iterable = client.listInspectTemplatesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listInspectTemplates.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listInspectTemplates.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listInspectTemplates with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listInspectTemplates.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listInspectTemplatesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IInspectTemplate[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listInspectTemplates.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listInspectTemplates.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listDeidentifyTemplates', () => { - it('invokes listDeidentifyTemplates without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - ]; - client.innerApiCalls.listDeidentifyTemplates = stubSimpleCall(expectedResponse); - const [response] = await client.listDeidentifyTemplates(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDeidentifyTemplates without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - ]; - client.innerApiCalls.listDeidentifyTemplates = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDeidentifyTemplates( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyTemplate[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDeidentifyTemplates with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDeidentifyTemplates = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listDeidentifyTemplates(request), expectedError); - const actualRequest = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDeidentifyTemplatesStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - ]; - client.descriptors.page.listDeidentifyTemplates.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listDeidentifyTemplatesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.DeidentifyTemplate[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.DeidentifyTemplate) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listDeidentifyTemplates.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDeidentifyTemplates, request)); - assert( - (client.descriptors.page.listDeidentifyTemplates.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listDeidentifyTemplatesStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDeidentifyTemplates.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listDeidentifyTemplatesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.DeidentifyTemplate[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.DeidentifyTemplate) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listDeidentifyTemplates.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDeidentifyTemplates, request)); - assert( - (client.descriptors.page.listDeidentifyTemplates.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDeidentifyTemplates without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - ]; - client.descriptors.page.listDeidentifyTemplates.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IDeidentifyTemplate[] = []; - const iterable = client.listDeidentifyTemplatesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listDeidentifyTemplates.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDeidentifyTemplates.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDeidentifyTemplates with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDeidentifyTemplates.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listDeidentifyTemplatesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IDeidentifyTemplate[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listDeidentifyTemplates.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDeidentifyTemplates.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listJobTriggers', () => { - it('invokes listJobTriggers without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - ]; - client.innerApiCalls.listJobTriggers = stubSimpleCall(expectedResponse); - const [response] = await client.listJobTriggers(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobTriggers without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - ]; - client.innerApiCalls.listJobTriggers = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listJobTriggers( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IJobTrigger[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobTriggers with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listJobTriggers = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listJobTriggers(request), expectedError); - const actualRequest = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobTriggersStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - ]; - client.descriptors.page.listJobTriggers.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listJobTriggersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.JobTrigger[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.JobTrigger) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listJobTriggers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listJobTriggers, request)); - assert( - (client.descriptors.page.listJobTriggers.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listJobTriggersStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listJobTriggers.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listJobTriggersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.JobTrigger[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.JobTrigger) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listJobTriggers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listJobTriggers, request)); - assert( - (client.descriptors.page.listJobTriggers.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listJobTriggers without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - ]; - client.descriptors.page.listJobTriggers.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IJobTrigger[] = []; - const iterable = client.listJobTriggersAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listJobTriggers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listJobTriggers.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listJobTriggers with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listJobTriggers.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listJobTriggersAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IJobTrigger[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listJobTriggers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listJobTriggers.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listDlpJobs', () => { - it('invokes listDlpJobs without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - ]; - client.innerApiCalls.listDlpJobs = stubSimpleCall(expectedResponse); - const [response] = await client.listDlpJobs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDlpJobs without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - ]; - client.innerApiCalls.listDlpJobs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDlpJobs( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDlpJob[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDlpJobs with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDlpJobs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listDlpJobs(request), expectedError); - const actualRequest = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDlpJobsStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - ]; - client.descriptors.page.listDlpJobs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listDlpJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.DlpJob[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.DlpJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listDlpJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDlpJobs, request)); - assert( - (client.descriptors.page.listDlpJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listDlpJobsStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDlpJobs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listDlpJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.DlpJob[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.DlpJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listDlpJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDlpJobs, request)); - assert( - (client.descriptors.page.listDlpJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDlpJobs without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - ]; - client.descriptors.page.listDlpJobs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IDlpJob[] = []; - const iterable = client.listDlpJobsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listDlpJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDlpJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDlpJobs with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDlpJobs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listDlpJobsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IDlpJob[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listDlpJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDlpJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listStoredInfoTypes', () => { - it('invokes listStoredInfoTypes without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - ]; - client.innerApiCalls.listStoredInfoTypes = stubSimpleCall(expectedResponse); - const [response] = await client.listStoredInfoTypes(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listStoredInfoTypes without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - ]; - client.innerApiCalls.listStoredInfoTypes = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listStoredInfoTypes( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IStoredInfoType[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listStoredInfoTypes with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listStoredInfoTypes = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listStoredInfoTypes(request), expectedError); - const actualRequest = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listStoredInfoTypesStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - ]; - client.descriptors.page.listStoredInfoTypes.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listStoredInfoTypesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.StoredInfoType[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.StoredInfoType) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listStoredInfoTypes.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listStoredInfoTypes, request)); - assert( - (client.descriptors.page.listStoredInfoTypes.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listStoredInfoTypesStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listStoredInfoTypes.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listStoredInfoTypesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.StoredInfoType[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.StoredInfoType) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listStoredInfoTypes.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listStoredInfoTypes, request)); - assert( - (client.descriptors.page.listStoredInfoTypes.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listStoredInfoTypes without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - ]; - client.descriptors.page.listStoredInfoTypes.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IStoredInfoType[] = []; - const iterable = client.listStoredInfoTypesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listStoredInfoTypes.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listStoredInfoTypes.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listStoredInfoTypes with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listStoredInfoTypes.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listStoredInfoTypesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IStoredInfoType[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listStoredInfoTypes.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listStoredInfoTypes.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('dlpJob', () => { - const fakePath = "/rendered/path/dlpJob"; - const expectedParameters = { - project: "projectValue", - dlp_job: "dlpJobValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.dlpJobPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.dlpJobPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('dlpJobPath', () => { - const result = client.dlpJobPath("projectValue", "dlpJobValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.dlpJobPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromDlpJobName', () => { - const result = client.matchProjectFromDlpJobName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.dlpJobPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchDlpJobFromDlpJobName', () => { - const result = client.matchDlpJobFromDlpJobName(fakePath); - assert.strictEqual(result, "dlpJobValue"); - assert((client.pathTemplates.dlpJobPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('jobTrigger', () => { - const fakePath = "/rendered/path/jobTrigger"; - const expectedParameters = { - project: "projectValue", - job_trigger: "jobTriggerValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.jobTriggerPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.jobTriggerPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('jobTriggerPath', () => { - const result = client.jobTriggerPath("projectValue", "jobTriggerValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.jobTriggerPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromJobTriggerName', () => { - const result = client.matchProjectFromJobTriggerName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.jobTriggerPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchJobTriggerFromJobTriggerName', () => { - const result = client.matchJobTriggerFromJobTriggerName(fakePath); - assert.strictEqual(result, "jobTriggerValue"); - assert((client.pathTemplates.jobTriggerPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organization', () => { - const fakePath = "/rendered/path/organization"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationPath', () => { - const result = client.organizationPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationName', () => { - const result = client.matchOrganizationFromOrganizationName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationDeidentifyTemplate', () => { - const fakePath = "/rendered/path/organizationDeidentifyTemplate"; - const expectedParameters = { - organization: "organizationValue", - deidentify_template: "deidentifyTemplateValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationDeidentifyTemplatePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationDeidentifyTemplatePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationDeidentifyTemplatePath', () => { - const result = client.organizationDeidentifyTemplatePath("organizationValue", "deidentifyTemplateValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationDeidentifyTemplatePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationDeidentifyTemplateName', () => { - const result = client.matchOrganizationFromOrganizationDeidentifyTemplateName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationDeidentifyTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchDeidentifyTemplateFromOrganizationDeidentifyTemplateName', () => { - const result = client.matchDeidentifyTemplateFromOrganizationDeidentifyTemplateName(fakePath); - assert.strictEqual(result, "deidentifyTemplateValue"); - assert((client.pathTemplates.organizationDeidentifyTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationInspectTemplate', () => { - const fakePath = "/rendered/path/organizationInspectTemplate"; - const expectedParameters = { - organization: "organizationValue", - inspect_template: "inspectTemplateValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationInspectTemplatePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationInspectTemplatePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationInspectTemplatePath', () => { - const result = client.organizationInspectTemplatePath("organizationValue", "inspectTemplateValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationInspectTemplatePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationInspectTemplateName', () => { - const result = client.matchOrganizationFromOrganizationInspectTemplateName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationInspectTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchInspectTemplateFromOrganizationInspectTemplateName', () => { - const result = client.matchInspectTemplateFromOrganizationInspectTemplateName(fakePath); - assert.strictEqual(result, "inspectTemplateValue"); - assert((client.pathTemplates.organizationInspectTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationStoredInfoType', () => { - const fakePath = "/rendered/path/organizationStoredInfoType"; - const expectedParameters = { - organization: "organizationValue", - stored_info_type: "storedInfoTypeValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationStoredInfoTypePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationStoredInfoTypePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationStoredInfoTypePath', () => { - const result = client.organizationStoredInfoTypePath("organizationValue", "storedInfoTypeValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationStoredInfoTypePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationStoredInfoTypeName', () => { - const result = client.matchOrganizationFromOrganizationStoredInfoTypeName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationStoredInfoTypePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchStoredInfoTypeFromOrganizationStoredInfoTypeName', () => { - const result = client.matchStoredInfoTypeFromOrganizationStoredInfoTypeName(fakePath); - assert.strictEqual(result, "storedInfoTypeValue"); - assert((client.pathTemplates.organizationStoredInfoTypePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectDeidentifyTemplate', () => { - const fakePath = "/rendered/path/projectDeidentifyTemplate"; - const expectedParameters = { - project: "projectValue", - deidentify_template: "deidentifyTemplateValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectDeidentifyTemplatePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectDeidentifyTemplatePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectDeidentifyTemplatePath', () => { - const result = client.projectDeidentifyTemplatePath("projectValue", "deidentifyTemplateValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectDeidentifyTemplatePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectDeidentifyTemplateName', () => { - const result = client.matchProjectFromProjectDeidentifyTemplateName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectDeidentifyTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchDeidentifyTemplateFromProjectDeidentifyTemplateName', () => { - const result = client.matchDeidentifyTemplateFromProjectDeidentifyTemplateName(fakePath); - assert.strictEqual(result, "deidentifyTemplateValue"); - assert((client.pathTemplates.projectDeidentifyTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectInspectTemplate', () => { - const fakePath = "/rendered/path/projectInspectTemplate"; - const expectedParameters = { - project: "projectValue", - inspect_template: "inspectTemplateValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectInspectTemplatePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectInspectTemplatePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectInspectTemplatePath', () => { - const result = client.projectInspectTemplatePath("projectValue", "inspectTemplateValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectInspectTemplatePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectInspectTemplateName', () => { - const result = client.matchProjectFromProjectInspectTemplateName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectInspectTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchInspectTemplateFromProjectInspectTemplateName', () => { - const result = client.matchInspectTemplateFromProjectInspectTemplateName(fakePath); - assert.strictEqual(result, "inspectTemplateValue"); - assert((client.pathTemplates.projectInspectTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectStoredInfoType', () => { - const fakePath = "/rendered/path/projectStoredInfoType"; - const expectedParameters = { - project: "projectValue", - stored_info_type: "storedInfoTypeValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectStoredInfoTypePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectStoredInfoTypePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectStoredInfoTypePath', () => { - const result = client.projectStoredInfoTypePath("projectValue", "storedInfoTypeValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectStoredInfoTypePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectStoredInfoTypeName', () => { - const result = client.matchProjectFromProjectStoredInfoTypeName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectStoredInfoTypePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchStoredInfoTypeFromProjectStoredInfoTypeName', () => { - const result = client.matchStoredInfoTypeFromProjectStoredInfoTypeName(fakePath); - assert.strictEqual(result, "storedInfoTypeValue"); - assert((client.pathTemplates.projectStoredInfoTypePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/package.json b/core/generator/gapic-generator-typescript/baselines/dlp-esm/package.json index 7f1c4d87c4af..7ea1e81f8969 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/dlp-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/dlp-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/dlp-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/dlp-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/dlp-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/dlp/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/dlp/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/package.json b/core/generator/gapic-generator-typescript/baselines/dlp/package.json index 9de123fa37a0..2dca224b06fc 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp/package.json +++ b/core/generator/gapic-generator-typescript/baselines/dlp/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 7a1ee11ebd0c..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const dlp = require('dlp'); - -function main() { - const dlpServiceClient = new dlp.DlpServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 9a3099a6afc2..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {DlpServiceClient} from 'dlp'; - -// check that the client class type name can be used -function doStuffWithDlpServiceClient(client: DlpServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const dlpServiceClient = new DlpServiceClient(); - doStuffWithDlpServiceClient(dlpServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/test/gapic_dlp_service_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/test/gapic_dlp_service_v2.ts.baseline deleted file mode 100644 index 0952f9f499eb..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/dlp/test/gapic_dlp_service_v2.ts.baseline +++ /dev/null @@ -1,4874 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as dlpserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.DlpServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new dlpserviceModule.v2.DlpServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'dlp.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new dlpserviceModule.v2.DlpServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = dlpserviceModule.v2.DlpServiceClient.servicePath; - assert.strictEqual(servicePath, 'dlp.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = dlpserviceModule.v2.DlpServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'dlp.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new dlpserviceModule.v2.DlpServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'dlp.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new dlpserviceModule.v2.DlpServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'dlp.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new dlpserviceModule.v2.DlpServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'dlp.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new dlpserviceModule.v2.DlpServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'dlp.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new dlpserviceModule.v2.DlpServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = dlpserviceModule.v2.DlpServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new dlpserviceModule.v2.DlpServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.dlpServiceStub, undefined); - await client.initialize(); - assert(client.dlpServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.dlpServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.dlpServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new dlpserviceModule.v2.DlpServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new dlpserviceModule.v2.DlpServiceClient({ - 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); - }); - }); - - describe('inspectContent', () => { - it('invokes inspectContent without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentResponse() - ); - client.innerApiCalls.inspectContent = stubSimpleCall(expectedResponse); - const [response] = await client.inspectContent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes inspectContent without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentResponse() - ); - client.innerApiCalls.inspectContent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.inspectContent( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectContentResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes inspectContent with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.inspectContent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.inspectContent(request), expectedError); - const actualRequest = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.inspectContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes inspectContent with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.InspectContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.inspectContent(request), expectedError); - }); - }); - - describe('redactImage', () => { - it('invokes redactImage without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageResponse() - ); - client.innerApiCalls.redactImage = stubSimpleCall(expectedResponse); - const [response] = await client.redactImage(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes redactImage without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageResponse() - ); - client.innerApiCalls.redactImage = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.redactImage( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IRedactImageResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes redactImage with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.redactImage = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.redactImage(request), expectedError); - const actualRequest = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.redactImage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes redactImage with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.RedactImageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.RedactImageRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.redactImage(request), expectedError); - }); - }); - - describe('deidentifyContent', () => { - it('invokes deidentifyContent without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentResponse() - ); - client.innerApiCalls.deidentifyContent = stubSimpleCall(expectedResponse); - const [response] = await client.deidentifyContent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deidentifyContent without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentResponse() - ); - client.innerApiCalls.deidentifyContent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deidentifyContent( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyContentResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deidentifyContent with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deidentifyContent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deidentifyContent(request), expectedError); - const actualRequest = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deidentifyContent with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deidentifyContent(request), expectedError); - }); - }); - - describe('reidentifyContent', () => { - it('invokes reidentifyContent without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentResponse() - ); - client.innerApiCalls.reidentifyContent = stubSimpleCall(expectedResponse); - const [response] = await client.reidentifyContent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reidentifyContent without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentResponse() - ); - client.innerApiCalls.reidentifyContent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.reidentifyContent( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IReidentifyContentResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reidentifyContent with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.reidentifyContent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.reidentifyContent(request), expectedError); - const actualRequest = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reidentifyContent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reidentifyContent with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ReidentifyContentRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ReidentifyContentRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.reidentifyContent(request), expectedError); - }); - }); - - describe('listInfoTypes', () => { - it('invokes listInfoTypes without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInfoTypesRequest', ['locationId']); - request.locationId = defaultValue1; - const expectedHeaderRequestParams = `location_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesResponse() - ); - client.innerApiCalls.listInfoTypes = stubSimpleCall(expectedResponse); - const [response] = await client.listInfoTypes(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInfoTypes without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInfoTypesRequest', ['locationId']); - request.locationId = defaultValue1; - const expectedHeaderRequestParams = `location_id=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesResponse() - ); - client.innerApiCalls.listInfoTypes = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listInfoTypes( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IListInfoTypesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInfoTypes with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInfoTypesRequest', ['locationId']); - request.locationId = defaultValue1; - const expectedHeaderRequestParams = `location_id=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listInfoTypes = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listInfoTypes(request), expectedError); - const actualRequest = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInfoTypes with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInfoTypesRequest', ['locationId']); - request.locationId = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listInfoTypes(request), expectedError); - }); - }); - - describe('createInspectTemplate', () => { - it('invokes createInspectTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.createInspectTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.createInspectTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInspectTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.createInspectTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createInspectTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInspectTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createInspectTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createInspectTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInspectTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateInspectTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createInspectTemplate(request), expectedError); - }); - }); - - describe('updateInspectTemplate', () => { - it('invokes updateInspectTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.updateInspectTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.updateInspectTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInspectTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.updateInspectTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateInspectTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInspectTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateInspectTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateInspectTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInspectTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateInspectTemplate(request), expectedError); - }); - }); - - describe('getInspectTemplate', () => { - it('invokes getInspectTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.getInspectTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.getInspectTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInspectTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.InspectTemplate() - ); - client.innerApiCalls.getInspectTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getInspectTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInspectTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getInspectTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getInspectTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInspectTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getInspectTemplate(request), expectedError); - }); - }); - - describe('deleteInspectTemplate', () => { - it('invokes deleteInspectTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteInspectTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.deleteInspectTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInspectTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteInspectTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteInspectTemplate( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInspectTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteInspectTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteInspectTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInspectTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInspectTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteInspectTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteInspectTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteInspectTemplate(request), expectedError); - }); - }); - - describe('createDeidentifyTemplate', () => { - it('invokes createDeidentifyTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.createDeidentifyTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.createDeidentifyTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDeidentifyTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.createDeidentifyTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createDeidentifyTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDeidentifyTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createDeidentifyTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createDeidentifyTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDeidentifyTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDeidentifyTemplateRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createDeidentifyTemplate(request), expectedError); - }); - }); - - describe('updateDeidentifyTemplate', () => { - it('invokes updateDeidentifyTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.updateDeidentifyTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.updateDeidentifyTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDeidentifyTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.updateDeidentifyTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateDeidentifyTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDeidentifyTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateDeidentifyTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateDeidentifyTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateDeidentifyTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateDeidentifyTemplate(request), expectedError); - }); - }); - - describe('getDeidentifyTemplate', () => { - it('invokes getDeidentifyTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.getDeidentifyTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.getDeidentifyTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDeidentifyTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeidentifyTemplate() - ); - client.innerApiCalls.getDeidentifyTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDeidentifyTemplate( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyTemplate|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDeidentifyTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDeidentifyTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDeidentifyTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDeidentifyTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDeidentifyTemplate(request), expectedError); - }); - }); - - describe('deleteDeidentifyTemplate', () => { - it('invokes deleteDeidentifyTemplate without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDeidentifyTemplate = stubSimpleCall(expectedResponse); - const [response] = await client.deleteDeidentifyTemplate(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDeidentifyTemplate without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDeidentifyTemplate = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDeidentifyTemplate( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDeidentifyTemplate with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDeidentifyTemplate = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteDeidentifyTemplate(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDeidentifyTemplate as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDeidentifyTemplate with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDeidentifyTemplateRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteDeidentifyTemplate(request), expectedError); - }); - }); - - describe('createJobTrigger', () => { - it('invokes createJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.createJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.createJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.createJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createJobTrigger( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IJobTrigger|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateJobTriggerRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createJobTrigger(request), expectedError); - }); - }); - - describe('updateJobTrigger', () => { - it('invokes updateJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.updateJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.updateJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.updateJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateJobTrigger( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IJobTrigger|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateJobTrigger(request), expectedError); - }); - }); - - describe('getJobTrigger', () => { - it('invokes getJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.getJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.getJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.JobTrigger() - ); - client.innerApiCalls.getJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getJobTrigger( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IJobTrigger|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getJobTrigger(request), expectedError); - }); - }); - - describe('deleteJobTrigger', () => { - it('invokes deleteJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.deleteJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteJobTrigger( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteJobTrigger(request), expectedError); - }); - }); - - describe('activateJobTrigger', () => { - it('invokes activateJobTrigger without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ActivateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ActivateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.activateJobTrigger = stubSimpleCall(expectedResponse); - const [response] = await client.activateJobTrigger(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes activateJobTrigger without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ActivateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ActivateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.activateJobTrigger = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.activateJobTrigger( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDlpJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes activateJobTrigger with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ActivateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ActivateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.activateJobTrigger = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.activateJobTrigger(request), expectedError); - const actualRequest = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.activateJobTrigger as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes activateJobTrigger with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ActivateJobTriggerRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ActivateJobTriggerRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.activateJobTrigger(request), expectedError); - }); - }); - - describe('createDlpJob', () => { - it('invokes createDlpJob without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.createDlpJob = stubSimpleCall(expectedResponse); - const [response] = await client.createDlpJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDlpJob without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.createDlpJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createDlpJob( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDlpJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDlpJob with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createDlpJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createDlpJob(request), expectedError); - const actualRequest = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createDlpJob with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateDlpJobRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createDlpJob(request), expectedError); - }); - }); - - describe('getDlpJob', () => { - it('invokes getDlpJob without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.getDlpJob = stubSimpleCall(expectedResponse); - const [response] = await client.getDlpJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDlpJob without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.DlpJob() - ); - client.innerApiCalls.getDlpJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDlpJob( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDlpJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDlpJob with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDlpJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDlpJob(request), expectedError); - const actualRequest = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDlpJob with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDlpJob(request), expectedError); - }); - }); - - describe('deleteDlpJob', () => { - it('invokes deleteDlpJob without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDlpJob = stubSimpleCall(expectedResponse); - const [response] = await client.deleteDlpJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDlpJob without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteDlpJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteDlpJob( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDlpJob with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteDlpJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteDlpJob(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteDlpJob with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteDlpJob(request), expectedError); - }); - }); - - describe('cancelDlpJob', () => { - it('invokes cancelDlpJob without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CancelDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CancelDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.cancelDlpJob = stubSimpleCall(expectedResponse); - const [response] = await client.cancelDlpJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelDlpJob without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CancelDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CancelDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.cancelDlpJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.cancelDlpJob( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelDlpJob with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CancelDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CancelDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.cancelDlpJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.cancelDlpJob(request), expectedError); - const actualRequest = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.cancelDlpJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes cancelDlpJob with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CancelDlpJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CancelDlpJobRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.cancelDlpJob(request), expectedError); - }); - }); - - describe('createStoredInfoType', () => { - it('invokes createStoredInfoType without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.createStoredInfoType = stubSimpleCall(expectedResponse); - const [response] = await client.createStoredInfoType(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createStoredInfoType without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.createStoredInfoType = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createStoredInfoType( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IStoredInfoType|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createStoredInfoType with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createStoredInfoType = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createStoredInfoType(request), expectedError); - const actualRequest = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createStoredInfoType with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.CreateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.CreateStoredInfoTypeRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createStoredInfoType(request), expectedError); - }); - }); - - describe('updateStoredInfoType', () => { - it('invokes updateStoredInfoType without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.updateStoredInfoType = stubSimpleCall(expectedResponse); - const [response] = await client.updateStoredInfoType(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateStoredInfoType without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.updateStoredInfoType = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateStoredInfoType( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IStoredInfoType|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateStoredInfoType with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateStoredInfoType = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateStoredInfoType(request), expectedError); - const actualRequest = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateStoredInfoType with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.UpdateStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateStoredInfoType(request), expectedError); - }); - }); - - describe('getStoredInfoType', () => { - it('invokes getStoredInfoType without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.getStoredInfoType = stubSimpleCall(expectedResponse); - const [response] = await client.getStoredInfoType(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getStoredInfoType without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.privacy.dlp.v2.StoredInfoType() - ); - client.innerApiCalls.getStoredInfoType = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getStoredInfoType( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IStoredInfoType|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getStoredInfoType with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getStoredInfoType = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getStoredInfoType(request), expectedError); - const actualRequest = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getStoredInfoType with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.GetStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.GetStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getStoredInfoType(request), expectedError); - }); - }); - - describe('deleteStoredInfoType', () => { - it('invokes deleteStoredInfoType without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteStoredInfoType = stubSimpleCall(expectedResponse); - const [response] = await client.deleteStoredInfoType(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteStoredInfoType without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteStoredInfoType = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteStoredInfoType( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteStoredInfoType with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteStoredInfoType = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteStoredInfoType(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteStoredInfoType as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteStoredInfoType with closed client', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.DeleteStoredInfoTypeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteStoredInfoType(request), expectedError); - }); - }); - - describe('listInspectTemplates', () => { - it('invokes listInspectTemplates without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - ]; - client.innerApiCalls.listInspectTemplates = stubSimpleCall(expectedResponse); - const [response] = await client.listInspectTemplates(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInspectTemplates without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - ]; - client.innerApiCalls.listInspectTemplates = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listInspectTemplates( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IInspectTemplate[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInspectTemplates with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listInspectTemplates = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listInspectTemplates(request), expectedError); - const actualRequest = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInspectTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInspectTemplatesStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - ]; - client.descriptors.page.listInspectTemplates.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listInspectTemplatesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.InspectTemplate[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.InspectTemplate) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listInspectTemplates.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listInspectTemplates, request)); - assert( - (client.descriptors.page.listInspectTemplates.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listInspectTemplatesStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listInspectTemplates.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listInspectTemplatesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.InspectTemplate[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.InspectTemplate) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listInspectTemplates.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listInspectTemplates, request)); - assert( - (client.descriptors.page.listInspectTemplates.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listInspectTemplates without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.InspectTemplate()), - ]; - client.descriptors.page.listInspectTemplates.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IInspectTemplate[] = []; - const iterable = client.listInspectTemplatesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listInspectTemplates.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listInspectTemplates.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listInspectTemplates with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListInspectTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListInspectTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listInspectTemplates.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listInspectTemplatesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IInspectTemplate[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listInspectTemplates.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listInspectTemplates.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listDeidentifyTemplates', () => { - it('invokes listDeidentifyTemplates without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - ]; - client.innerApiCalls.listDeidentifyTemplates = stubSimpleCall(expectedResponse); - const [response] = await client.listDeidentifyTemplates(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDeidentifyTemplates without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - ]; - client.innerApiCalls.listDeidentifyTemplates = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDeidentifyTemplates( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDeidentifyTemplate[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDeidentifyTemplates with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDeidentifyTemplates = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listDeidentifyTemplates(request), expectedError); - const actualRequest = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDeidentifyTemplates as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDeidentifyTemplatesStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - ]; - client.descriptors.page.listDeidentifyTemplates.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listDeidentifyTemplatesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.DeidentifyTemplate[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.DeidentifyTemplate) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listDeidentifyTemplates.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDeidentifyTemplates, request)); - assert( - (client.descriptors.page.listDeidentifyTemplates.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listDeidentifyTemplatesStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDeidentifyTemplates.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listDeidentifyTemplatesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.DeidentifyTemplate[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.DeidentifyTemplate) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listDeidentifyTemplates.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDeidentifyTemplates, request)); - assert( - (client.descriptors.page.listDeidentifyTemplates.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDeidentifyTemplates without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DeidentifyTemplate()), - ]; - client.descriptors.page.listDeidentifyTemplates.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IDeidentifyTemplate[] = []; - const iterable = client.listDeidentifyTemplatesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listDeidentifyTemplates.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDeidentifyTemplates.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDeidentifyTemplates with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDeidentifyTemplatesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDeidentifyTemplates.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listDeidentifyTemplatesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IDeidentifyTemplate[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listDeidentifyTemplates.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDeidentifyTemplates.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listJobTriggers', () => { - it('invokes listJobTriggers without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - ]; - client.innerApiCalls.listJobTriggers = stubSimpleCall(expectedResponse); - const [response] = await client.listJobTriggers(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobTriggers without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - ]; - client.innerApiCalls.listJobTriggers = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listJobTriggers( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IJobTrigger[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobTriggers with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listJobTriggers = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listJobTriggers(request), expectedError); - const actualRequest = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listJobTriggers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listJobTriggersStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - ]; - client.descriptors.page.listJobTriggers.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listJobTriggersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.JobTrigger[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.JobTrigger) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listJobTriggers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listJobTriggers, request)); - assert( - (client.descriptors.page.listJobTriggers.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listJobTriggersStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listJobTriggers.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listJobTriggersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.JobTrigger[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.JobTrigger) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listJobTriggers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listJobTriggers, request)); - assert( - (client.descriptors.page.listJobTriggers.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listJobTriggers without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - generateSampleMessage(new protos.google.privacy.dlp.v2.JobTrigger()), - ]; - client.descriptors.page.listJobTriggers.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IJobTrigger[] = []; - const iterable = client.listJobTriggersAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listJobTriggers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listJobTriggers.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listJobTriggers with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListJobTriggersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListJobTriggersRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listJobTriggers.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listJobTriggersAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IJobTrigger[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listJobTriggers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listJobTriggers.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listDlpJobs', () => { - it('invokes listDlpJobs without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - ]; - client.innerApiCalls.listDlpJobs = stubSimpleCall(expectedResponse); - const [response] = await client.listDlpJobs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDlpJobs without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - ]; - client.innerApiCalls.listDlpJobs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listDlpJobs( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IDlpJob[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDlpJobs with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listDlpJobs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listDlpJobs(request), expectedError); - const actualRequest = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listDlpJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listDlpJobsStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - ]; - client.descriptors.page.listDlpJobs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listDlpJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.DlpJob[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.DlpJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listDlpJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDlpJobs, request)); - assert( - (client.descriptors.page.listDlpJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listDlpJobsStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDlpJobs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listDlpJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.DlpJob[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.DlpJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listDlpJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listDlpJobs, request)); - assert( - (client.descriptors.page.listDlpJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDlpJobs without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - generateSampleMessage(new protos.google.privacy.dlp.v2.DlpJob()), - ]; - client.descriptors.page.listDlpJobs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IDlpJob[] = []; - const iterable = client.listDlpJobsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listDlpJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDlpJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listDlpJobs with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListDlpJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListDlpJobsRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listDlpJobs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listDlpJobsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IDlpJob[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listDlpJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listDlpJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listStoredInfoTypes', () => { - it('invokes listStoredInfoTypes without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - ]; - client.innerApiCalls.listStoredInfoTypes = stubSimpleCall(expectedResponse); - const [response] = await client.listStoredInfoTypes(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listStoredInfoTypes without error using callback', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - ]; - client.innerApiCalls.listStoredInfoTypes = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listStoredInfoTypes( - request, - (err?: Error|null, result?: protos.google.privacy.dlp.v2.IStoredInfoType[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listStoredInfoTypes with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listStoredInfoTypes = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listStoredInfoTypes(request), expectedError); - const actualRequest = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listStoredInfoTypes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listStoredInfoTypesStream without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - ]; - client.descriptors.page.listStoredInfoTypes.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listStoredInfoTypesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.StoredInfoType[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.StoredInfoType) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listStoredInfoTypes.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listStoredInfoTypes, request)); - assert( - (client.descriptors.page.listStoredInfoTypes.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listStoredInfoTypesStream with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listStoredInfoTypes.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listStoredInfoTypesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.privacy.dlp.v2.StoredInfoType[] = []; - stream.on('data', (response: protos.google.privacy.dlp.v2.StoredInfoType) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listStoredInfoTypes.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listStoredInfoTypes, request)); - assert( - (client.descriptors.page.listStoredInfoTypes.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listStoredInfoTypes without error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - generateSampleMessage(new protos.google.privacy.dlp.v2.StoredInfoType()), - ]; - client.descriptors.page.listStoredInfoTypes.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.privacy.dlp.v2.IStoredInfoType[] = []; - const iterable = client.listStoredInfoTypesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listStoredInfoTypes.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listStoredInfoTypes.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listStoredInfoTypes with error', async () => { - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.privacy.dlp.v2.ListStoredInfoTypesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['parent']); - request.parent = defaultValue1; - const defaultValue2 = - getTypeDefaultValue('.google.privacy.dlp.v2.ListStoredInfoTypesRequest', ['locationId']); - request.locationId = defaultValue2; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }&location_id=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listStoredInfoTypes.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listStoredInfoTypesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.privacy.dlp.v2.IStoredInfoType[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listStoredInfoTypes.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listStoredInfoTypes.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('dlpJob', async () => { - const fakePath = "/rendered/path/dlpJob"; - const expectedParameters = { - project: "projectValue", - dlp_job: "dlpJobValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.dlpJobPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.dlpJobPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('dlpJobPath', () => { - const result = client.dlpJobPath("projectValue", "dlpJobValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.dlpJobPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromDlpJobName', () => { - const result = client.matchProjectFromDlpJobName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.dlpJobPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchDlpJobFromDlpJobName', () => { - const result = client.matchDlpJobFromDlpJobName(fakePath); - assert.strictEqual(result, "dlpJobValue"); - assert((client.pathTemplates.dlpJobPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('jobTrigger', async () => { - const fakePath = "/rendered/path/jobTrigger"; - const expectedParameters = { - project: "projectValue", - job_trigger: "jobTriggerValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.jobTriggerPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.jobTriggerPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('jobTriggerPath', () => { - const result = client.jobTriggerPath("projectValue", "jobTriggerValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.jobTriggerPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromJobTriggerName', () => { - const result = client.matchProjectFromJobTriggerName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.jobTriggerPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchJobTriggerFromJobTriggerName', () => { - const result = client.matchJobTriggerFromJobTriggerName(fakePath); - assert.strictEqual(result, "jobTriggerValue"); - assert((client.pathTemplates.jobTriggerPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organization', async () => { - const fakePath = "/rendered/path/organization"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationPath', () => { - const result = client.organizationPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationName', () => { - const result = client.matchOrganizationFromOrganizationName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationDeidentifyTemplate', async () => { - const fakePath = "/rendered/path/organizationDeidentifyTemplate"; - const expectedParameters = { - organization: "organizationValue", - deidentify_template: "deidentifyTemplateValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationDeidentifyTemplatePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationDeidentifyTemplatePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationDeidentifyTemplatePath', () => { - const result = client.organizationDeidentifyTemplatePath("organizationValue", "deidentifyTemplateValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationDeidentifyTemplatePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationDeidentifyTemplateName', () => { - const result = client.matchOrganizationFromOrganizationDeidentifyTemplateName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationDeidentifyTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchDeidentifyTemplateFromOrganizationDeidentifyTemplateName', () => { - const result = client.matchDeidentifyTemplateFromOrganizationDeidentifyTemplateName(fakePath); - assert.strictEqual(result, "deidentifyTemplateValue"); - assert((client.pathTemplates.organizationDeidentifyTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationInspectTemplate', async () => { - const fakePath = "/rendered/path/organizationInspectTemplate"; - const expectedParameters = { - organization: "organizationValue", - inspect_template: "inspectTemplateValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationInspectTemplatePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationInspectTemplatePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationInspectTemplatePath', () => { - const result = client.organizationInspectTemplatePath("organizationValue", "inspectTemplateValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationInspectTemplatePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationInspectTemplateName', () => { - const result = client.matchOrganizationFromOrganizationInspectTemplateName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationInspectTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchInspectTemplateFromOrganizationInspectTemplateName', () => { - const result = client.matchInspectTemplateFromOrganizationInspectTemplateName(fakePath); - assert.strictEqual(result, "inspectTemplateValue"); - assert((client.pathTemplates.organizationInspectTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationStoredInfoType', async () => { - const fakePath = "/rendered/path/organizationStoredInfoType"; - const expectedParameters = { - organization: "organizationValue", - stored_info_type: "storedInfoTypeValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationStoredInfoTypePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationStoredInfoTypePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationStoredInfoTypePath', () => { - const result = client.organizationStoredInfoTypePath("organizationValue", "storedInfoTypeValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationStoredInfoTypePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationStoredInfoTypeName', () => { - const result = client.matchOrganizationFromOrganizationStoredInfoTypeName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationStoredInfoTypePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchStoredInfoTypeFromOrganizationStoredInfoTypeName', () => { - const result = client.matchStoredInfoTypeFromOrganizationStoredInfoTypeName(fakePath); - assert.strictEqual(result, "storedInfoTypeValue"); - assert((client.pathTemplates.organizationStoredInfoTypePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectDeidentifyTemplate', async () => { - const fakePath = "/rendered/path/projectDeidentifyTemplate"; - const expectedParameters = { - project: "projectValue", - deidentify_template: "deidentifyTemplateValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectDeidentifyTemplatePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectDeidentifyTemplatePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectDeidentifyTemplatePath', () => { - const result = client.projectDeidentifyTemplatePath("projectValue", "deidentifyTemplateValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectDeidentifyTemplatePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectDeidentifyTemplateName', () => { - const result = client.matchProjectFromProjectDeidentifyTemplateName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectDeidentifyTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchDeidentifyTemplateFromProjectDeidentifyTemplateName', () => { - const result = client.matchDeidentifyTemplateFromProjectDeidentifyTemplateName(fakePath); - assert.strictEqual(result, "deidentifyTemplateValue"); - assert((client.pathTemplates.projectDeidentifyTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectInspectTemplate', async () => { - const fakePath = "/rendered/path/projectInspectTemplate"; - const expectedParameters = { - project: "projectValue", - inspect_template: "inspectTemplateValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectInspectTemplatePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectInspectTemplatePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectInspectTemplatePath', () => { - const result = client.projectInspectTemplatePath("projectValue", "inspectTemplateValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectInspectTemplatePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectInspectTemplateName', () => { - const result = client.matchProjectFromProjectInspectTemplateName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectInspectTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchInspectTemplateFromProjectInspectTemplateName', () => { - const result = client.matchInspectTemplateFromProjectInspectTemplateName(fakePath); - assert.strictEqual(result, "inspectTemplateValue"); - assert((client.pathTemplates.projectInspectTemplatePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectStoredInfoType', async () => { - const fakePath = "/rendered/path/projectStoredInfoType"; - const expectedParameters = { - project: "projectValue", - stored_info_type: "storedInfoTypeValue", - }; - const client = new dlpserviceModule.v2.DlpServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectStoredInfoTypePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectStoredInfoTypePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectStoredInfoTypePath', () => { - const result = client.projectStoredInfoTypePath("projectValue", "storedInfoTypeValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectStoredInfoTypePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectStoredInfoTypeName', () => { - const result = client.matchProjectFromProjectStoredInfoTypeName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectStoredInfoTypePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchStoredInfoTypeFromProjectStoredInfoTypeName', () => { - const result = client.matchStoredInfoTypeFromProjectStoredInfoTypeName(fakePath); - assert.strictEqual(result, "storedInfoTypeValue"); - assert((client.pathTemplates.projectStoredInfoTypePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/dlp/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/dlp/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/dlp/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/dlp/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/kms-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/kms-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 23d692b452e9..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const kms = require('kms'); - -function main() { - const keyManagementServiceClient = new kms.KeyManagementServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 471d47ca9875..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as kms from 'kms'; - -function main() { - const keyManagementServiceClient = new kms.KeyManagementServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 8c695e4b03b2..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {KeyManagementServiceClient} from 'kms'; - -// check that the client class type name can be used -function doStuffWithKeyManagementServiceClient(client: KeyManagementServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const keyManagementServiceClient = new KeyManagementServiceClient(); - doStuffWithKeyManagementServiceClient(keyManagementServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/test/gapic_key_management_service_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/test/gapic_key_management_service_v1.ts.baseline deleted file mode 100644 index a70096f09c23..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/esm/test/gapic_key_management_service_v1.ts.baseline +++ /dev/null @@ -1,3586 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as keymanagementserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, IamProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.KeyManagementServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudkms.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = keymanagementserviceModule.v1.KeyManagementServiceClient.servicePath; - assert.strictEqual(servicePath, 'cloudkms.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = keymanagementserviceModule.v1.KeyManagementServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudkms.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudkms.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudkms.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudkms.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudkms.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new keymanagementserviceModule.v1.KeyManagementServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = keymanagementserviceModule.v1.KeyManagementServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.keyManagementServiceStub, undefined); - await client.initialize(); - assert(client.keyManagementServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.keyManagementServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.keyManagementServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - 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); - }); - }); - - describe('getKeyRing', () => { - it('invokes getKeyRing without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetKeyRingRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.KeyRing() - ); - client.innerApiCalls.getKeyRing = stubSimpleCall(expectedResponse); - const [response] = await client.getKeyRing(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getKeyRing without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetKeyRingRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.KeyRing() - ); - client.innerApiCalls.getKeyRing = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getKeyRing( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IKeyRing|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getKeyRing with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetKeyRingRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getKeyRing = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getKeyRing(request), expectedError); - const actualRequest = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getKeyRing with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetKeyRingRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getKeyRing(request), expectedError); - }); - }); - - describe('getCryptoKey', () => { - it('invokes getCryptoKey without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.getCryptoKey = stubSimpleCall(expectedResponse); - const [response] = await client.getCryptoKey(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKey without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.getCryptoKey = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getCryptoKey( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKey with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getCryptoKey = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getCryptoKey(request), expectedError); - const actualRequest = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKey with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getCryptoKey(request), expectedError); - }); - }); - - describe('getCryptoKeyVersion', () => { - it('invokes getCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.getCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.getCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.getCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getCryptoKeyVersion(request), expectedError); - }); - }); - - describe('getPublicKey', () => { - it('invokes getPublicKey without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetPublicKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetPublicKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.PublicKey() - ); - client.innerApiCalls.getPublicKey = stubSimpleCall(expectedResponse); - const [response] = await client.getPublicKey(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getPublicKey without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetPublicKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetPublicKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.PublicKey() - ); - client.innerApiCalls.getPublicKey = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getPublicKey( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IPublicKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getPublicKey with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetPublicKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetPublicKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getPublicKey = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getPublicKey(request), expectedError); - const actualRequest = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getPublicKey with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetPublicKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetPublicKeyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getPublicKey(request), expectedError); - }); - }); - - describe('getImportJob', () => { - it('invokes getImportJob without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetImportJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportJob() - ); - client.innerApiCalls.getImportJob = stubSimpleCall(expectedResponse); - const [response] = await client.getImportJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getImportJob without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetImportJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportJob() - ); - client.innerApiCalls.getImportJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getImportJob( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IImportJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getImportJob with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetImportJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getImportJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getImportJob(request), expectedError); - const actualRequest = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getImportJob with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetImportJobRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getImportJob(request), expectedError); - }); - }); - - describe('createKeyRing', () => { - it('invokes createKeyRing without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateKeyRingRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.KeyRing() - ); - client.innerApiCalls.createKeyRing = stubSimpleCall(expectedResponse); - const [response] = await client.createKeyRing(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createKeyRing without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateKeyRingRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.KeyRing() - ); - client.innerApiCalls.createKeyRing = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createKeyRing( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IKeyRing|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createKeyRing with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateKeyRingRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createKeyRing = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createKeyRing(request), expectedError); - const actualRequest = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createKeyRing with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateKeyRingRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createKeyRing(request), expectedError); - }); - }); - - describe('createCryptoKey', () => { - it('invokes createCryptoKey without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.createCryptoKey = stubSimpleCall(expectedResponse); - const [response] = await client.createCryptoKey(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKey without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.createCryptoKey = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createCryptoKey( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKey with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createCryptoKey = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createCryptoKey(request), expectedError); - const actualRequest = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKey with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createCryptoKey(request), expectedError); - }); - }); - - describe('createCryptoKeyVersion', () => { - it('invokes createCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.createCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.createCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.createCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createCryptoKeyVersion(request), expectedError); - }); - }); - - describe('importCryptoKeyVersion', () => { - it('invokes importCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ImportCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.importCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.importCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ImportCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.importCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ImportCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.importCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ImportCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.importCryptoKeyVersion(request), expectedError); - }); - }); - - describe('createImportJob', () => { - it('invokes createImportJob without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateImportJobRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportJob() - ); - client.innerApiCalls.createImportJob = stubSimpleCall(expectedResponse); - const [response] = await client.createImportJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createImportJob without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateImportJobRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportJob() - ); - client.innerApiCalls.createImportJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createImportJob( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IImportJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createImportJob with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateImportJobRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createImportJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createImportJob(request), expectedError); - const actualRequest = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createImportJob with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateImportJobRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createImportJob(request), expectedError); - }); - }); - - describe('updateCryptoKey', () => { - it('invokes updateCryptoKey without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyRequest() - ); - request.cryptoKey ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyRequest', ['cryptoKey', 'name']); - request.cryptoKey.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.updateCryptoKey = stubSimpleCall(expectedResponse); - const [response] = await client.updateCryptoKey(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKey without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyRequest() - ); - request.cryptoKey ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyRequest', ['cryptoKey', 'name']); - request.cryptoKey.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.updateCryptoKey = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCryptoKey( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKey with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyRequest() - ); - request.cryptoKey ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyRequest', ['cryptoKey', 'name']); - request.cryptoKey.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCryptoKey = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCryptoKey(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKey with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyRequest() - ); - request.cryptoKey ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyRequest', ['cryptoKey', 'name']); - request.cryptoKey.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCryptoKey(request), expectedError); - }); - }); - - describe('updateCryptoKeyVersion', () => { - it('invokes updateCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest() - ); - request.cryptoKeyVersion ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest', ['cryptoKeyVersion', 'name']); - request.cryptoKeyVersion.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key_version.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.updateCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.updateCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest() - ); - request.cryptoKeyVersion ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest', ['cryptoKeyVersion', 'name']); - request.cryptoKeyVersion.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key_version.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.updateCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest() - ); - request.cryptoKeyVersion ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest', ['cryptoKeyVersion', 'name']); - request.cryptoKeyVersion.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key_version.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest() - ); - request.cryptoKeyVersion ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest', ['cryptoKeyVersion', 'name']); - request.cryptoKeyVersion.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCryptoKeyVersion(request), expectedError); - }); - }); - - describe('encrypt', () => { - it('invokes encrypt without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.EncryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptResponse() - ); - client.innerApiCalls.encrypt = stubSimpleCall(expectedResponse); - const [response] = await client.encrypt(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes encrypt without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.EncryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptResponse() - ); - client.innerApiCalls.encrypt = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.encrypt( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IEncryptResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes encrypt with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.EncryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.encrypt = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.encrypt(request), expectedError); - const actualRequest = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes encrypt with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.EncryptRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.encrypt(request), expectedError); - }); - }); - - describe('decrypt', () => { - it('invokes decrypt without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptResponse() - ); - client.innerApiCalls.decrypt = stubSimpleCall(expectedResponse); - const [response] = await client.decrypt(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes decrypt without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptResponse() - ); - client.innerApiCalls.decrypt = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.decrypt( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IDecryptResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes decrypt with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.decrypt = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.decrypt(request), expectedError); - const actualRequest = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes decrypt with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DecryptRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.decrypt(request), expectedError); - }); - }); - - describe('asymmetricSign', () => { - it('invokes asymmetricSign without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricSignRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignResponse() - ); - client.innerApiCalls.asymmetricSign = stubSimpleCall(expectedResponse); - const [response] = await client.asymmetricSign(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricSign without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricSignRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignResponse() - ); - client.innerApiCalls.asymmetricSign = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.asymmetricSign( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IAsymmetricSignResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricSign with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricSignRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.asymmetricSign = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.asymmetricSign(request), expectedError); - const actualRequest = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricSign with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricSignRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.asymmetricSign(request), expectedError); - }); - }); - - describe('asymmetricDecrypt', () => { - it('invokes asymmetricDecrypt without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricDecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptResponse() - ); - client.innerApiCalls.asymmetricDecrypt = stubSimpleCall(expectedResponse); - const [response] = await client.asymmetricDecrypt(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricDecrypt without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricDecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptResponse() - ); - client.innerApiCalls.asymmetricDecrypt = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.asymmetricDecrypt( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IAsymmetricDecryptResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricDecrypt with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricDecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.asymmetricDecrypt = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.asymmetricDecrypt(request), expectedError); - const actualRequest = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricDecrypt with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricDecryptRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.asymmetricDecrypt(request), expectedError); - }); - }); - - describe('updateCryptoKeyPrimaryVersion', () => { - it('invokes updateCryptoKeyPrimaryVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.updateCryptoKeyPrimaryVersion = stubSimpleCall(expectedResponse); - const [response] = await client.updateCryptoKeyPrimaryVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyPrimaryVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.updateCryptoKeyPrimaryVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCryptoKeyPrimaryVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyPrimaryVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCryptoKeyPrimaryVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCryptoKeyPrimaryVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyPrimaryVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCryptoKeyPrimaryVersion(request), expectedError); - }); - }); - - describe('destroyCryptoKeyVersion', () => { - it('invokes destroyCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.destroyCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.destroyCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes destroyCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.destroyCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.destroyCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes destroyCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.destroyCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.destroyCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes destroyCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.destroyCryptoKeyVersion(request), expectedError); - }); - }); - - describe('restoreCryptoKeyVersion', () => { - it('invokes restoreCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.restoreCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.restoreCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.restoreCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.restoreCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.restoreCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.restoreCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.restoreCryptoKeyVersion(request), expectedError); - }); - }); - - describe('listKeyRings', () => { - it('invokes listKeyRings without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - ]; - client.innerApiCalls.listKeyRings = stubSimpleCall(expectedResponse); - const [response] = await client.listKeyRings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listKeyRings without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - ]; - client.innerApiCalls.listKeyRings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listKeyRings( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IKeyRing[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listKeyRings with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listKeyRings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listKeyRings(request), expectedError); - const actualRequest = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listKeyRingsStream without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - ]; - client.descriptors.page.listKeyRings.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listKeyRingsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.KeyRing[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.KeyRing) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listKeyRings.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listKeyRings, request)); - assert( - (client.descriptors.page.listKeyRings.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listKeyRingsStream with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listKeyRings.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listKeyRingsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.KeyRing[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.KeyRing) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listKeyRings.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listKeyRings, request)); - assert( - (client.descriptors.page.listKeyRings.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listKeyRings without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - ]; - client.descriptors.page.listKeyRings.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.kms.v1.IKeyRing[] = []; - const iterable = client.listKeyRingsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listKeyRings.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listKeyRings.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listKeyRings with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listKeyRings.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listKeyRingsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.kms.v1.IKeyRing[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listKeyRings.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listKeyRings.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listCryptoKeys', () => { - it('invokes listCryptoKeys without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - ]; - client.innerApiCalls.listCryptoKeys = stubSimpleCall(expectedResponse); - const [response] = await client.listCryptoKeys(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeys without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - ]; - client.innerApiCalls.listCryptoKeys = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listCryptoKeys( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeys with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listCryptoKeys = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listCryptoKeys(request), expectedError); - const actualRequest = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeysStream without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - ]; - client.descriptors.page.listCryptoKeys.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listCryptoKeysStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.CryptoKey[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.CryptoKey) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listCryptoKeys.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCryptoKeys, request)); - assert( - (client.descriptors.page.listCryptoKeys.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listCryptoKeysStream with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCryptoKeys.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listCryptoKeysStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.CryptoKey[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.CryptoKey) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listCryptoKeys.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCryptoKeys, request)); - assert( - (client.descriptors.page.listCryptoKeys.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCryptoKeys without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - ]; - client.descriptors.page.listCryptoKeys.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.kms.v1.ICryptoKey[] = []; - const iterable = client.listCryptoKeysAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listCryptoKeys.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCryptoKeys.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCryptoKeys with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCryptoKeys.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listCryptoKeysAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.kms.v1.ICryptoKey[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listCryptoKeys.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCryptoKeys.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listCryptoKeyVersions', () => { - it('invokes listCryptoKeyVersions without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - ]; - client.innerApiCalls.listCryptoKeyVersions = stubSimpleCall(expectedResponse); - const [response] = await client.listCryptoKeyVersions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeyVersions without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - ]; - client.innerApiCalls.listCryptoKeyVersions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listCryptoKeyVersions( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeyVersions with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listCryptoKeyVersions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listCryptoKeyVersions(request), expectedError); - const actualRequest = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeyVersionsStream without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - ]; - client.descriptors.page.listCryptoKeyVersions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listCryptoKeyVersionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.CryptoKeyVersion[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.CryptoKeyVersion) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listCryptoKeyVersions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCryptoKeyVersions, request)); - assert( - (client.descriptors.page.listCryptoKeyVersions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listCryptoKeyVersionsStream with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCryptoKeyVersions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listCryptoKeyVersionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.CryptoKeyVersion[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.CryptoKeyVersion) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listCryptoKeyVersions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCryptoKeyVersions, request)); - assert( - (client.descriptors.page.listCryptoKeyVersions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCryptoKeyVersions without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - ]; - client.descriptors.page.listCryptoKeyVersions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.kms.v1.ICryptoKeyVersion[] = []; - const iterable = client.listCryptoKeyVersionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listCryptoKeyVersions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCryptoKeyVersions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCryptoKeyVersions with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCryptoKeyVersions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listCryptoKeyVersionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.kms.v1.ICryptoKeyVersion[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listCryptoKeyVersions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCryptoKeyVersions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listImportJobs', () => { - it('invokes listImportJobs without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - ]; - client.innerApiCalls.listImportJobs = stubSimpleCall(expectedResponse); - const [response] = await client.listImportJobs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listImportJobs without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - ]; - client.innerApiCalls.listImportJobs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listImportJobs( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IImportJob[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listImportJobs with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listImportJobs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listImportJobs(request), expectedError); - const actualRequest = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listImportJobsStream without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - ]; - client.descriptors.page.listImportJobs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listImportJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.ImportJob[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.ImportJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listImportJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listImportJobs, request)); - assert( - (client.descriptors.page.listImportJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listImportJobsStream with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listImportJobs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listImportJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.ImportJob[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.ImportJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listImportJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listImportJobs, request)); - assert( - (client.descriptors.page.listImportJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listImportJobs without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - ]; - client.descriptors.page.listImportJobs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.kms.v1.IImportJob[] = []; - const iterable = client.listImportJobsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listImportJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listImportJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listImportJobs with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listImportJobs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listImportJobsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.kms.v1.IImportJob[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listImportJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listImportJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.getIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes getIamPolicy without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes getIamPolicy with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.getIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.setIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes setIamPolicy without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes setIamPolicy with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); - const response = await client.testIamPermissions(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes testIamPermissions without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.testIamPermissions( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0)); - }); - it('invokes testIamPermissions with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/package.json b/core/generator/gapic-generator-typescript/baselines/kms-esm/package.json index afb55956344b..c99d31d0b25c 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/kms-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/kms-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/kms-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/kms-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/kms-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/kms/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/kms/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/kms/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/kms/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/kms/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/kms/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/kms/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/kms/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/kms/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/kms/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/kms/package.json b/core/generator/gapic-generator-typescript/baselines/kms/package.json index 407ed881406f..e0f3b1fe2353 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms/package.json +++ b/core/generator/gapic-generator-typescript/baselines/kms/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/kms/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/kms/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 87a29ad6830b..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const kms = require('kms'); - -function main() { - const keyManagementServiceClient = new kms.KeyManagementServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/kms/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/kms/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index b3732005b505..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {KeyManagementServiceClient} from 'kms'; - -// check that the client class type name can be used -function doStuffWithKeyManagementServiceClient(client: KeyManagementServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const keyManagementServiceClient = new KeyManagementServiceClient(); - doStuffWithKeyManagementServiceClient(keyManagementServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/kms/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/kms/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/kms/test/gapic_key_management_service_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/kms/test/gapic_key_management_service_v1.ts.baseline deleted file mode 100644 index b0382f4b2d22..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/kms/test/gapic_key_management_service_v1.ts.baseline +++ /dev/null @@ -1,3577 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as keymanagementserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, IamProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1.KeyManagementServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudkms.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = keymanagementserviceModule.v1.KeyManagementServiceClient.servicePath; - assert.strictEqual(servicePath, 'cloudkms.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = keymanagementserviceModule.v1.KeyManagementServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudkms.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudkms.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudkms.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudkms.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudkms.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new keymanagementserviceModule.v1.KeyManagementServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = keymanagementserviceModule.v1.KeyManagementServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.keyManagementServiceStub, undefined); - await client.initialize(); - assert(client.keyManagementServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.keyManagementServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.keyManagementServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - 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); - }); - }); - - describe('getKeyRing', () => { - it('invokes getKeyRing without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetKeyRingRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.KeyRing() - ); - client.innerApiCalls.getKeyRing = stubSimpleCall(expectedResponse); - const [response] = await client.getKeyRing(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getKeyRing without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetKeyRingRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.KeyRing() - ); - client.innerApiCalls.getKeyRing = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getKeyRing( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IKeyRing|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getKeyRing with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetKeyRingRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getKeyRing = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getKeyRing(request), expectedError); - const actualRequest = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getKeyRing with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetKeyRingRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getKeyRing(request), expectedError); - }); - }); - - describe('getCryptoKey', () => { - it('invokes getCryptoKey without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.getCryptoKey = stubSimpleCall(expectedResponse); - const [response] = await client.getCryptoKey(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKey without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.getCryptoKey = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getCryptoKey( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKey with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getCryptoKey = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getCryptoKey(request), expectedError); - const actualRequest = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKey with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getCryptoKey(request), expectedError); - }); - }); - - describe('getCryptoKeyVersion', () => { - it('invokes getCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.getCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.getCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.getCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getCryptoKeyVersion(request), expectedError); - }); - }); - - describe('getPublicKey', () => { - it('invokes getPublicKey without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetPublicKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetPublicKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.PublicKey() - ); - client.innerApiCalls.getPublicKey = stubSimpleCall(expectedResponse); - const [response] = await client.getPublicKey(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getPublicKey without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetPublicKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetPublicKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.PublicKey() - ); - client.innerApiCalls.getPublicKey = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getPublicKey( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IPublicKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getPublicKey with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetPublicKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetPublicKeyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getPublicKey = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getPublicKey(request), expectedError); - const actualRequest = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getPublicKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getPublicKey with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetPublicKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetPublicKeyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getPublicKey(request), expectedError); - }); - }); - - describe('getImportJob', () => { - it('invokes getImportJob without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetImportJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportJob() - ); - client.innerApiCalls.getImportJob = stubSimpleCall(expectedResponse); - const [response] = await client.getImportJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getImportJob without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetImportJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportJob() - ); - client.innerApiCalls.getImportJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getImportJob( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IImportJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getImportJob with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetImportJobRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getImportJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getImportJob(request), expectedError); - const actualRequest = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getImportJob with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.GetImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.GetImportJobRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getImportJob(request), expectedError); - }); - }); - - describe('createKeyRing', () => { - it('invokes createKeyRing without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateKeyRingRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.KeyRing() - ); - client.innerApiCalls.createKeyRing = stubSimpleCall(expectedResponse); - const [response] = await client.createKeyRing(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createKeyRing without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateKeyRingRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.KeyRing() - ); - client.innerApiCalls.createKeyRing = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createKeyRing( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IKeyRing|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createKeyRing with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateKeyRingRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createKeyRing = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createKeyRing(request), expectedError); - const actualRequest = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createKeyRing as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createKeyRing with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateKeyRingRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateKeyRingRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createKeyRing(request), expectedError); - }); - }); - - describe('createCryptoKey', () => { - it('invokes createCryptoKey without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.createCryptoKey = stubSimpleCall(expectedResponse); - const [response] = await client.createCryptoKey(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKey without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.createCryptoKey = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createCryptoKey( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKey with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createCryptoKey = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createCryptoKey(request), expectedError); - const actualRequest = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKey with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createCryptoKey(request), expectedError); - }); - }); - - describe('createCryptoKeyVersion', () => { - it('invokes createCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.createCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.createCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.createCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createCryptoKeyVersion(request), expectedError); - }); - }); - - describe('importCryptoKeyVersion', () => { - it('invokes importCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ImportCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.importCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.importCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ImportCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.importCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ImportCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.importCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ImportCryptoKeyVersionRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.importCryptoKeyVersion(request), expectedError); - }); - }); - - describe('createImportJob', () => { - it('invokes createImportJob without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateImportJobRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportJob() - ); - client.innerApiCalls.createImportJob = stubSimpleCall(expectedResponse); - const [response] = await client.createImportJob(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createImportJob without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateImportJobRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.ImportJob() - ); - client.innerApiCalls.createImportJob = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createImportJob( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IImportJob|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createImportJob with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateImportJobRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createImportJob = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createImportJob(request), expectedError); - const actualRequest = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createImportJob as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createImportJob with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.CreateImportJobRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.CreateImportJobRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createImportJob(request), expectedError); - }); - }); - - describe('updateCryptoKey', () => { - it('invokes updateCryptoKey without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyRequest() - ); - request.cryptoKey ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyRequest', ['cryptoKey', 'name']); - request.cryptoKey.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.updateCryptoKey = stubSimpleCall(expectedResponse); - const [response] = await client.updateCryptoKey(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKey without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyRequest() - ); - request.cryptoKey ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyRequest', ['cryptoKey', 'name']); - request.cryptoKey.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.updateCryptoKey = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCryptoKey( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKey with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyRequest() - ); - request.cryptoKey ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyRequest', ['cryptoKey', 'name']); - request.cryptoKey.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCryptoKey = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCryptoKey(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKey as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKey with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyRequest() - ); - request.cryptoKey ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyRequest', ['cryptoKey', 'name']); - request.cryptoKey.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCryptoKey(request), expectedError); - }); - }); - - describe('updateCryptoKeyVersion', () => { - it('invokes updateCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest() - ); - request.cryptoKeyVersion ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest', ['cryptoKeyVersion', 'name']); - request.cryptoKeyVersion.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key_version.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.updateCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.updateCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest() - ); - request.cryptoKeyVersion ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest', ['cryptoKeyVersion', 'name']); - request.cryptoKeyVersion.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key_version.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.updateCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest() - ); - request.cryptoKeyVersion ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest', ['cryptoKeyVersion', 'name']); - request.cryptoKeyVersion.name = defaultValue1; - const expectedHeaderRequestParams = `crypto_key_version.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest() - ); - request.cryptoKeyVersion ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyVersionRequest', ['cryptoKeyVersion', 'name']); - request.cryptoKeyVersion.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCryptoKeyVersion(request), expectedError); - }); - }); - - describe('encrypt', () => { - it('invokes encrypt without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.EncryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptResponse() - ); - client.innerApiCalls.encrypt = stubSimpleCall(expectedResponse); - const [response] = await client.encrypt(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes encrypt without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.EncryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptResponse() - ); - client.innerApiCalls.encrypt = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.encrypt( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IEncryptResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes encrypt with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.EncryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.encrypt = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.encrypt(request), expectedError); - const actualRequest = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.encrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes encrypt with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.EncryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.EncryptRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.encrypt(request), expectedError); - }); - }); - - describe('decrypt', () => { - it('invokes decrypt without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptResponse() - ); - client.innerApiCalls.decrypt = stubSimpleCall(expectedResponse); - const [response] = await client.decrypt(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes decrypt without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptResponse() - ); - client.innerApiCalls.decrypt = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.decrypt( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IDecryptResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes decrypt with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.decrypt = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.decrypt(request), expectedError); - const actualRequest = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.decrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes decrypt with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DecryptRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.decrypt(request), expectedError); - }); - }); - - describe('asymmetricSign', () => { - it('invokes asymmetricSign without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricSignRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignResponse() - ); - client.innerApiCalls.asymmetricSign = stubSimpleCall(expectedResponse); - const [response] = await client.asymmetricSign(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricSign without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricSignRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignResponse() - ); - client.innerApiCalls.asymmetricSign = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.asymmetricSign( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IAsymmetricSignResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricSign with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricSignRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.asymmetricSign = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.asymmetricSign(request), expectedError); - const actualRequest = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricSign as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricSign with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricSignRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricSignRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.asymmetricSign(request), expectedError); - }); - }); - - describe('asymmetricDecrypt', () => { - it('invokes asymmetricDecrypt without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricDecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptResponse() - ); - client.innerApiCalls.asymmetricDecrypt = stubSimpleCall(expectedResponse); - const [response] = await client.asymmetricDecrypt(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricDecrypt without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricDecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptResponse() - ); - client.innerApiCalls.asymmetricDecrypt = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.asymmetricDecrypt( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IAsymmetricDecryptResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricDecrypt with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricDecryptRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.asymmetricDecrypt = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.asymmetricDecrypt(request), expectedError); - const actualRequest = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.asymmetricDecrypt as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes asymmetricDecrypt with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.AsymmetricDecryptRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.AsymmetricDecryptRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.asymmetricDecrypt(request), expectedError); - }); - }); - - describe('updateCryptoKeyPrimaryVersion', () => { - it('invokes updateCryptoKeyPrimaryVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.updateCryptoKeyPrimaryVersion = stubSimpleCall(expectedResponse); - const [response] = await client.updateCryptoKeyPrimaryVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyPrimaryVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKey() - ); - client.innerApiCalls.updateCryptoKeyPrimaryVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCryptoKeyPrimaryVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyPrimaryVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCryptoKeyPrimaryVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCryptoKeyPrimaryVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCryptoKeyPrimaryVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCryptoKeyPrimaryVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.UpdateCryptoKeyPrimaryVersionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCryptoKeyPrimaryVersion(request), expectedError); - }); - }); - - describe('destroyCryptoKeyVersion', () => { - it('invokes destroyCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.destroyCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.destroyCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes destroyCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.destroyCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.destroyCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes destroyCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.destroyCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.destroyCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.destroyCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes destroyCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.DestroyCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.destroyCryptoKeyVersion(request), expectedError); - }); - }); - - describe('restoreCryptoKeyVersion', () => { - it('invokes restoreCryptoKeyVersion without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.restoreCryptoKeyVersion = stubSimpleCall(expectedResponse); - const [response] = await client.restoreCryptoKeyVersion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreCryptoKeyVersion without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.kms.v1.CryptoKeyVersion() - ); - client.innerApiCalls.restoreCryptoKeyVersion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.restoreCryptoKeyVersion( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreCryptoKeyVersion with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.restoreCryptoKeyVersion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.restoreCryptoKeyVersion(request), expectedError); - const actualRequest = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.restoreCryptoKeyVersion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes restoreCryptoKeyVersion with closed client', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.RestoreCryptoKeyVersionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.restoreCryptoKeyVersion(request), expectedError); - }); - }); - - describe('listKeyRings', () => { - it('invokes listKeyRings without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - ]; - client.innerApiCalls.listKeyRings = stubSimpleCall(expectedResponse); - const [response] = await client.listKeyRings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listKeyRings without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - ]; - client.innerApiCalls.listKeyRings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listKeyRings( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IKeyRing[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listKeyRings with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listKeyRings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listKeyRings(request), expectedError); - const actualRequest = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listKeyRings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listKeyRingsStream without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - ]; - client.descriptors.page.listKeyRings.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listKeyRingsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.KeyRing[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.KeyRing) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listKeyRings.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listKeyRings, request)); - assert( - (client.descriptors.page.listKeyRings.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listKeyRingsStream with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listKeyRings.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listKeyRingsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.KeyRing[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.KeyRing) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listKeyRings.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listKeyRings, request)); - assert( - (client.descriptors.page.listKeyRings.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listKeyRings without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - generateSampleMessage(new protos.google.cloud.kms.v1.KeyRing()), - ]; - client.descriptors.page.listKeyRings.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.kms.v1.IKeyRing[] = []; - const iterable = client.listKeyRingsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listKeyRings.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listKeyRings.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listKeyRings with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListKeyRingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListKeyRingsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listKeyRings.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listKeyRingsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.kms.v1.IKeyRing[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listKeyRings.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listKeyRings.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listCryptoKeys', () => { - it('invokes listCryptoKeys without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - ]; - client.innerApiCalls.listCryptoKeys = stubSimpleCall(expectedResponse); - const [response] = await client.listCryptoKeys(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeys without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - ]; - client.innerApiCalls.listCryptoKeys = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listCryptoKeys( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKey[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeys with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listCryptoKeys = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listCryptoKeys(request), expectedError); - const actualRequest = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeys as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeysStream without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - ]; - client.descriptors.page.listCryptoKeys.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listCryptoKeysStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.CryptoKey[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.CryptoKey) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listCryptoKeys.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCryptoKeys, request)); - assert( - (client.descriptors.page.listCryptoKeys.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listCryptoKeysStream with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCryptoKeys.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listCryptoKeysStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.CryptoKey[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.CryptoKey) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listCryptoKeys.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCryptoKeys, request)); - assert( - (client.descriptors.page.listCryptoKeys.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCryptoKeys without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKey()), - ]; - client.descriptors.page.listCryptoKeys.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.kms.v1.ICryptoKey[] = []; - const iterable = client.listCryptoKeysAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listCryptoKeys.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCryptoKeys.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCryptoKeys with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeysRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeysRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCryptoKeys.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listCryptoKeysAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.kms.v1.ICryptoKey[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listCryptoKeys.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCryptoKeys.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listCryptoKeyVersions', () => { - it('invokes listCryptoKeyVersions without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - ]; - client.innerApiCalls.listCryptoKeyVersions = stubSimpleCall(expectedResponse); - const [response] = await client.listCryptoKeyVersions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeyVersions without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - ]; - client.innerApiCalls.listCryptoKeyVersions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listCryptoKeyVersions( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.ICryptoKeyVersion[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeyVersions with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listCryptoKeyVersions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listCryptoKeyVersions(request), expectedError); - const actualRequest = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCryptoKeyVersions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCryptoKeyVersionsStream without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - ]; - client.descriptors.page.listCryptoKeyVersions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listCryptoKeyVersionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.CryptoKeyVersion[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.CryptoKeyVersion) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listCryptoKeyVersions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCryptoKeyVersions, request)); - assert( - (client.descriptors.page.listCryptoKeyVersions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listCryptoKeyVersionsStream with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCryptoKeyVersions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listCryptoKeyVersionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.CryptoKeyVersion[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.CryptoKeyVersion) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listCryptoKeyVersions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCryptoKeyVersions, request)); - assert( - (client.descriptors.page.listCryptoKeyVersions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCryptoKeyVersions without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - generateSampleMessage(new protos.google.cloud.kms.v1.CryptoKeyVersion()), - ]; - client.descriptors.page.listCryptoKeyVersions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.kms.v1.ICryptoKeyVersion[] = []; - const iterable = client.listCryptoKeyVersionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listCryptoKeyVersions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCryptoKeyVersions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCryptoKeyVersions with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListCryptoKeyVersionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListCryptoKeyVersionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCryptoKeyVersions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listCryptoKeyVersionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.kms.v1.ICryptoKeyVersion[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listCryptoKeyVersions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCryptoKeyVersions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listImportJobs', () => { - it('invokes listImportJobs without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - ]; - client.innerApiCalls.listImportJobs = stubSimpleCall(expectedResponse); - const [response] = await client.listImportJobs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listImportJobs without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - ]; - client.innerApiCalls.listImportJobs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listImportJobs( - request, - (err?: Error|null, result?: protos.google.cloud.kms.v1.IImportJob[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listImportJobs with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listImportJobs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listImportJobs(request), expectedError); - const actualRequest = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listImportJobs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listImportJobsStream without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - ]; - client.descriptors.page.listImportJobs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listImportJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.ImportJob[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.ImportJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listImportJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listImportJobs, request)); - assert( - (client.descriptors.page.listImportJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listImportJobsStream with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listImportJobs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listImportJobsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.kms.v1.ImportJob[] = []; - stream.on('data', (response: protos.google.cloud.kms.v1.ImportJob) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listImportJobs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listImportJobs, request)); - assert( - (client.descriptors.page.listImportJobs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listImportJobs without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - generateSampleMessage(new protos.google.cloud.kms.v1.ImportJob()), - ]; - client.descriptors.page.listImportJobs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.kms.v1.IImportJob[] = []; - const iterable = client.listImportJobsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listImportJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listImportJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listImportJobs with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.kms.v1.ListImportJobsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.kms.v1.ListImportJobsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listImportJobs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listImportJobsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.kms.v1.IImportJob[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listImportJobs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listImportJobs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.getIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes getIamPolicy without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.getIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes getIamPolicy with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.GetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.getIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.getIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = stubSimpleCall(expectedResponse); - const response = await client.setIamPolicy(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes setIamPolicy without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.Policy() - ); - client.iamClient.setIamPolicy = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setIamPolicy( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.Policy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0)); - }); - it('invokes setIamPolicy with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.SetIamPolicyRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.setIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setIamPolicy(request, expectedOptions), expectedError); - assert((client.iamClient.setIamPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = stubSimpleCall(expectedResponse); - const response = await client.testIamPermissions(request, expectedOptions); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - it('invokes testIamPermissions without error using callback', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsResponse() - ); - client.iamClient.testIamPermissions = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.testIamPermissions( - request, - expectedOptions, - (err?: Error|null, result?: IamProtos.google.iam.v1.TestIamPermissionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0)); - }); - it('invokes testIamPermissions with error', async () => { - const client = new keymanagementserviceModule.v1.KeyManagementServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new IamProtos.google.iam.v1.TestIamPermissionsRequest() - ); - request.resource = ''; - const expectedHeaderRequestParams = 'resource='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.iamClient.testIamPermissions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.testIamPermissions(request, expectedOptions), expectedError); - assert((client.iamClient.testIamPermissions as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/kms/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/kms/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/kms/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/kms/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/logging-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/logging-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 679906fceb22..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const logging = require('logging'); - -function main() { - const configServiceV2Client = new logging.ConfigServiceV2Client(); - const loggingServiceV2Client = new logging.LoggingServiceV2Client(); - const metricsServiceV2Client = new logging.MetricsServiceV2Client(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 487c17f61940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as logging from 'logging'; - -function main() { - const configServiceV2Client = new logging.ConfigServiceV2Client(); - const loggingServiceV2Client = new logging.LoggingServiceV2Client(); - const metricsServiceV2Client = new logging.MetricsServiceV2Client(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 51f52bae60f7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,45 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {ConfigServiceV2Client, LoggingServiceV2Client, MetricsServiceV2Client} from 'logging'; - -// check that the client class type name can be used -function doStuffWithConfigServiceV2Client(client: ConfigServiceV2Client) { - client.close(); -} -function doStuffWithLoggingServiceV2Client(client: LoggingServiceV2Client) { - client.close(); -} -function doStuffWithMetricsServiceV2Client(client: MetricsServiceV2Client) { - client.close(); -} - -function main() { - // check that the client instance can be created - const configServiceV2Client = new ConfigServiceV2Client(); - doStuffWithConfigServiceV2Client(configServiceV2Client); - // check that the client instance can be created - const loggingServiceV2Client = new LoggingServiceV2Client(); - doStuffWithLoggingServiceV2Client(loggingServiceV2Client); - // check that the client instance can be created - const metricsServiceV2Client = new MetricsServiceV2Client(); - doStuffWithMetricsServiceV2Client(metricsServiceV2Client); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_config_service_v2_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_config_service_v2_v2.ts.baseline deleted file mode 100644 index b8ce1e24b5ea..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_config_service_v2_v2.ts.baseline +++ /dev/null @@ -1,4853 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as configservicev2Module from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.ConfigServiceV2Client', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = configservicev2Module.v2.ConfigServiceV2Client.servicePath; - assert.strictEqual(servicePath, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = configservicev2Module.v2.ConfigServiceV2Client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new configservicev2Module.v2.ConfigServiceV2Client(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new configservicev2Module.v2.ConfigServiceV2Client({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new configservicev2Module.v2.ConfigServiceV2Client({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = configservicev2Module.v2.ConfigServiceV2Client.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.configServiceV2Stub, undefined); - await client.initialize(); - assert(client.configServiceV2Stub); - }); - - it('has close method for the initialized client', done => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.configServiceV2Stub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.configServiceV2Stub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - 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); - }); - }); - - describe('getBucket', () => { - it('invokes getBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.getBucket = stubSimpleCall(expectedResponse); - const [response] = await client.getBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.getBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBucket( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogBucket|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetBucketRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBucket(request), expectedError); - }); - }); - - describe('createBucket', () => { - it('invokes createBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateBucketRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.createBucket = stubSimpleCall(expectedResponse); - const [response] = await client.createBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateBucketRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.createBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBucket( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogBucket|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateBucketRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateBucketRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createBucket(request), expectedError); - }); - }); - - describe('updateBucket', () => { - it('invokes updateBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.updateBucket = stubSimpleCall(expectedResponse); - const [response] = await client.updateBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.updateBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBucket( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogBucket|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateBucketRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateBucket(request), expectedError); - }); - }); - - describe('deleteBucket', () => { - it('invokes deleteBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBucket = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBucket( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteBucket(request), expectedError); - }); - }); - - describe('undeleteBucket', () => { - it('invokes undeleteBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UndeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UndeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.undeleteBucket = stubSimpleCall(expectedResponse); - const [response] = await client.undeleteBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UndeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UndeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.undeleteBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.undeleteBucket( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UndeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UndeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.undeleteBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.undeleteBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UndeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UndeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.undeleteBucket(request), expectedError); - }); - }); - - describe('getView', () => { - it('invokes getView without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.getView = stubSimpleCall(expectedResponse); - const [response] = await client.getView(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getView without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.getView = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getView( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogView|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getView with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getView = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getView(request), expectedError); - const actualRequest = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getView with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetViewRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getView(request), expectedError); - }); - }); - - describe('createView', () => { - it('invokes createView without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateViewRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.createView = stubSimpleCall(expectedResponse); - const [response] = await client.createView(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createView without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateViewRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.createView = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createView( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogView|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createView with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateViewRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createView = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createView(request), expectedError); - const actualRequest = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createView with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateViewRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createView(request), expectedError); - }); - }); - - describe('updateView', () => { - it('invokes updateView without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.updateView = stubSimpleCall(expectedResponse); - const [response] = await client.updateView(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateView without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.updateView = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateView( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogView|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateView with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateView = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateView(request), expectedError); - const actualRequest = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateView with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateViewRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateView(request), expectedError); - }); - }); - - describe('deleteView', () => { - it('invokes deleteView without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteView = stubSimpleCall(expectedResponse); - const [response] = await client.deleteView(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteView without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteView = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteView( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteView with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteView = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteView(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteView with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteViewRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteView(request), expectedError); - }); - }); - - describe('getSink', () => { - it('invokes getSink without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.getSink = stubSimpleCall(expectedResponse); - const [response] = await client.getSink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSink without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.getSink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSink( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogSink|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSink with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSink(request), expectedError); - const actualRequest = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSink with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSink(request), expectedError); - }); - }); - - describe('createSink', () => { - it('invokes createSink without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateSinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.createSink = stubSimpleCall(expectedResponse); - const [response] = await client.createSink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSink without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateSinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.createSink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSink( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogSink|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSink with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateSinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createSink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSink(request), expectedError); - const actualRequest = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSink with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateSinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSink(request), expectedError); - }); - }); - - describe('updateSink', () => { - it('invokes updateSink without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.updateSink = stubSimpleCall(expectedResponse); - const [response] = await client.updateSink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSink without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.updateSink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateSink( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogSink|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSink with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateSink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateSink(request), expectedError); - const actualRequest = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSink with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateSink(request), expectedError); - }); - }); - - describe('deleteSink', () => { - it('invokes deleteSink without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSink = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSink without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSink( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSink with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSink(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSink with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteSink(request), expectedError); - }); - }); - - describe('getExclusion', () => { - it('invokes getExclusion without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.getExclusion = stubSimpleCall(expectedResponse); - const [response] = await client.getExclusion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getExclusion without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.getExclusion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getExclusion( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogExclusion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getExclusion with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getExclusion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getExclusion(request), expectedError); - const actualRequest = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getExclusion with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getExclusion(request), expectedError); - }); - }); - - describe('createExclusion', () => { - it('invokes createExclusion without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateExclusionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.createExclusion = stubSimpleCall(expectedResponse); - const [response] = await client.createExclusion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createExclusion without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateExclusionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.createExclusion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createExclusion( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogExclusion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createExclusion with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateExclusionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createExclusion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createExclusion(request), expectedError); - const actualRequest = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createExclusion with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateExclusionRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createExclusion(request), expectedError); - }); - }); - - describe('updateExclusion', () => { - it('invokes updateExclusion without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.updateExclusion = stubSimpleCall(expectedResponse); - const [response] = await client.updateExclusion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateExclusion without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.updateExclusion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateExclusion( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogExclusion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateExclusion with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateExclusion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateExclusion(request), expectedError); - const actualRequest = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateExclusion with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateExclusion(request), expectedError); - }); - }); - - describe('deleteExclusion', () => { - it('invokes deleteExclusion without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteExclusion = stubSimpleCall(expectedResponse); - const [response] = await client.deleteExclusion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteExclusion without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteExclusion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteExclusion( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteExclusion with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteExclusion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteExclusion(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteExclusion with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteExclusion(request), expectedError); - }); - }); - - describe('getCmekSettings', () => { - it('invokes getCmekSettings without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.CmekSettings() - ); - client.innerApiCalls.getCmekSettings = stubSimpleCall(expectedResponse); - const [response] = await client.getCmekSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCmekSettings without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.CmekSettings() - ); - client.innerApiCalls.getCmekSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getCmekSettings( - request, - (err?: Error|null, result?: protos.google.logging.v2.ICmekSettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCmekSettings with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getCmekSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getCmekSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCmekSettings with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getCmekSettings(request), expectedError); - }); - }); - - describe('updateCmekSettings', () => { - it('invokes updateCmekSettings without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.CmekSettings() - ); - client.innerApiCalls.updateCmekSettings = stubSimpleCall(expectedResponse); - const [response] = await client.updateCmekSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCmekSettings without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.CmekSettings() - ); - client.innerApiCalls.updateCmekSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCmekSettings( - request, - (err?: Error|null, result?: protos.google.logging.v2.ICmekSettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCmekSettings with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCmekSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCmekSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCmekSettings with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCmekSettings(request), expectedError); - }); - }); - - describe('getSettings', () => { - it('invokes getSettings without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.Settings() - ); - client.innerApiCalls.getSettings = stubSimpleCall(expectedResponse); - const [response] = await client.getSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSettings without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.Settings() - ); - client.innerApiCalls.getSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSettings( - request, - (err?: Error|null, result?: protos.google.logging.v2.ISettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSettings with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSettings with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSettings(request), expectedError); - }); - }); - - describe('updateSettings', () => { - it('invokes updateSettings without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.Settings() - ); - client.innerApiCalls.updateSettings = stubSimpleCall(expectedResponse); - const [response] = await client.updateSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSettings without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.Settings() - ); - client.innerApiCalls.updateSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateSettings( - request, - (err?: Error|null, result?: protos.google.logging.v2.ISettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSettings with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSettings with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateSettings(request), expectedError); - }); - }); - - describe('copyLogEntries', () => { - it('invokes copyLogEntries without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CopyLogEntriesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.copyLogEntries = stubLongRunningCall(expectedResponse); - const [operation] = await client.copyLogEntries(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes copyLogEntries without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CopyLogEntriesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.copyLogEntries = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.copyLogEntries( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes copyLogEntries with call error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CopyLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.copyLogEntries = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.copyLogEntries(request), expectedError); - }); - - it('invokes copyLogEntries with LRO error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CopyLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.copyLogEntries = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.copyLogEntries(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkCopyLogEntriesProgress without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCopyLogEntriesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCopyLogEntriesProgress with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCopyLogEntriesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listBuckets', () => { - it('invokes listBuckets without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - ]; - client.innerApiCalls.listBuckets = stubSimpleCall(expectedResponse); - const [response] = await client.listBuckets(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBuckets without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - ]; - client.innerApiCalls.listBuckets = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBuckets( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogBucket[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBuckets with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBuckets = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBuckets(request), expectedError); - const actualRequest = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBucketsStream without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - ]; - client.descriptors.page.listBuckets.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listBucketsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogBucket[] = []; - stream.on('data', (response: protos.google.logging.v2.LogBucket) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listBuckets.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBuckets, request)); - assert( - (client.descriptors.page.listBuckets.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listBucketsStream with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBuckets.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listBucketsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogBucket[] = []; - stream.on('data', (response: protos.google.logging.v2.LogBucket) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listBuckets.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBuckets, request)); - assert( - (client.descriptors.page.listBuckets.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBuckets without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - ]; - client.descriptors.page.listBuckets.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogBucket[] = []; - const iterable = client.listBucketsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listBuckets.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBuckets.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBuckets with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBuckets.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBucketsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogBucket[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listBuckets.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBuckets.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listViews', () => { - it('invokes listViews without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - ]; - client.innerApiCalls.listViews = stubSimpleCall(expectedResponse); - const [response] = await client.listViews(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listViews without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - ]; - client.innerApiCalls.listViews = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listViews( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogView[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listViews with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listViews = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listViews(request), expectedError); - const actualRequest = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listViewsStream without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - ]; - client.descriptors.page.listViews.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listViewsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogView[] = []; - stream.on('data', (response: protos.google.logging.v2.LogView) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listViews.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listViews, request)); - assert( - (client.descriptors.page.listViews.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listViewsStream with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listViews.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listViewsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogView[] = []; - stream.on('data', (response: protos.google.logging.v2.LogView) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listViews.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listViews, request)); - assert( - (client.descriptors.page.listViews.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listViews without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - ]; - client.descriptors.page.listViews.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogView[] = []; - const iterable = client.listViewsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listViews.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listViews.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listViews with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listViews.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listViewsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogView[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listViews.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listViews.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listSinks', () => { - it('invokes listSinks without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - ]; - client.innerApiCalls.listSinks = stubSimpleCall(expectedResponse); - const [response] = await client.listSinks(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSinks without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - ]; - client.innerApiCalls.listSinks = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSinks( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogSink[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSinks with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listSinks = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSinks(request), expectedError); - const actualRequest = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSinksStream without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - ]; - client.descriptors.page.listSinks.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSinksStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogSink[] = []; - stream.on('data', (response: protos.google.logging.v2.LogSink) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listSinks.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSinks, request)); - assert( - (client.descriptors.page.listSinks.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listSinksStream with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listSinks.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSinksStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogSink[] = []; - stream.on('data', (response: protos.google.logging.v2.LogSink) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSinks.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSinks, request)); - assert( - (client.descriptors.page.listSinks.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSinks without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - ]; - client.descriptors.page.listSinks.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogSink[] = []; - const iterable = client.listSinksAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSinks.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSinks.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSinks with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listSinks.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSinksAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogSink[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSinks.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSinks.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listExclusions', () => { - it('invokes listExclusions without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - ]; - client.innerApiCalls.listExclusions = stubSimpleCall(expectedResponse); - const [response] = await client.listExclusions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listExclusions without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - ]; - client.innerApiCalls.listExclusions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listExclusions( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogExclusion[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listExclusions with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listExclusions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listExclusions(request), expectedError); - const actualRequest = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listExclusionsStream without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - ]; - client.descriptors.page.listExclusions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listExclusionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogExclusion[] = []; - stream.on('data', (response: protos.google.logging.v2.LogExclusion) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listExclusions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listExclusions, request)); - assert( - (client.descriptors.page.listExclusions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listExclusionsStream with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listExclusions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listExclusionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogExclusion[] = []; - stream.on('data', (response: protos.google.logging.v2.LogExclusion) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listExclusions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listExclusions, request)); - assert( - (client.descriptors.page.listExclusions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listExclusions without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - ]; - client.descriptors.page.listExclusions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogExclusion[] = []; - const iterable = client.listExclusionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listExclusions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listExclusions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listExclusions with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listExclusions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listExclusionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogExclusion[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listExclusions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listExclusions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('billingAccountCmekSettings', () => { - const fakePath = "/rendered/path/billingAccountCmekSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountCmekSettingsPath', () => { - const result = client.billingAccountCmekSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountCmekSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountCmekSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountExclusion', () => { - const fakePath = "/rendered/path/billingAccountExclusion"; - const expectedParameters = { - billing_account: "billingAccountValue", - exclusion: "exclusionValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountExclusionPath', () => { - const result = client.billingAccountExclusionPath("billingAccountValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountExclusionName', () => { - const result = client.matchBillingAccountFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromBillingAccountExclusionName', () => { - const result = client.matchExclusionFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucket', () => { - const fakePath = "/rendered/path/billingAccountLocationBucket"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketPath', () => { - const result = client.billingAccountLocationBucketPath("billingAccountValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucketView', () => { - const fakePath = "/rendered/path/billingAccountLocationBucketView"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketViewPath', () => { - const result = client.billingAccountLocationBucketViewPath("billingAccountValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketViewName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromBillingAccountLocationBucketViewName', () => { - const result = client.matchViewFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLog', () => { - const fakePath = "/rendered/path/billingAccountLog"; - const expectedParameters = { - billing_account: "billingAccountValue", - log: "logValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLogPath', () => { - const result = client.billingAccountLogPath("billingAccountValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLogName', () => { - const result = client.matchBillingAccountFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromBillingAccountLogName', () => { - const result = client.matchLogFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSettings', () => { - const fakePath = "/rendered/path/billingAccountSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSettingsPath', () => { - const result = client.billingAccountSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSink', () => { - const fakePath = "/rendered/path/billingAccountSink"; - const expectedParameters = { - billing_account: "billingAccountValue", - sink: "sinkValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSinkPath', () => { - const result = client.billingAccountSinkPath("billingAccountValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSinkName', () => { - const result = client.matchBillingAccountFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromBillingAccountSinkName', () => { - const result = client.matchSinkFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderCmekSettings', () => { - const fakePath = "/rendered/path/folderCmekSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderCmekSettingsPath', () => { - const result = client.folderCmekSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderCmekSettingsName', () => { - const result = client.matchFolderFromFolderCmekSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderExclusion', () => { - const fakePath = "/rendered/path/folderExclusion"; - const expectedParameters = { - folder: "folderValue", - exclusion: "exclusionValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderExclusionPath', () => { - const result = client.folderExclusionPath("folderValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderExclusionName', () => { - const result = client.matchFolderFromFolderExclusionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromFolderExclusionName', () => { - const result = client.matchExclusionFromFolderExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucket', () => { - const fakePath = "/rendered/path/folderLocationBucket"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketPath', () => { - const result = client.folderLocationBucketPath("folderValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketName', () => { - const result = client.matchFolderFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketName', () => { - const result = client.matchLocationFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketName', () => { - const result = client.matchBucketFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucketView', () => { - const fakePath = "/rendered/path/folderLocationBucketView"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketViewPath', () => { - const result = client.folderLocationBucketViewPath("folderValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketViewName', () => { - const result = client.matchFolderFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketViewName', () => { - const result = client.matchLocationFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketViewName', () => { - const result = client.matchBucketFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromFolderLocationBucketViewName', () => { - const result = client.matchViewFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLog', () => { - const fakePath = "/rendered/path/folderLog"; - const expectedParameters = { - folder: "folderValue", - log: "logValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLogPath', () => { - const result = client.folderLogPath("folderValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLogName', () => { - const result = client.matchFolderFromFolderLogName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromFolderLogName', () => { - const result = client.matchLogFromFolderLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSettings', () => { - const fakePath = "/rendered/path/folderSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSettingsPath', () => { - const result = client.folderSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSettingsName', () => { - const result = client.matchFolderFromFolderSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSink', () => { - const fakePath = "/rendered/path/folderSink"; - const expectedParameters = { - folder: "folderValue", - sink: "sinkValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSinkPath', () => { - const result = client.folderSinkPath("folderValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSinkName', () => { - const result = client.matchFolderFromFolderSinkName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromFolderSinkName', () => { - const result = client.matchSinkFromFolderSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('location', () => { - const fakePath = "/rendered/path/location"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.locationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.locationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath("projectValue", "locationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('logMetric', () => { - const fakePath = "/rendered/path/logMetric"; - const expectedParameters = { - project: "projectValue", - metric: "metricValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.logMetricPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.logMetricPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('logMetricPath', () => { - const result = client.logMetricPath("projectValue", "metricValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.logMetricPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLogMetricName', () => { - const result = client.matchProjectFromLogMetricName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricFromLogMetricName', () => { - const result = client.matchMetricFromLogMetricName(fakePath); - assert.strictEqual(result, "metricValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationCmekSettings', () => { - const fakePath = "/rendered/path/organizationCmekSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationCmekSettingsPath', () => { - const result = client.organizationCmekSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationCmekSettingsName', () => { - const result = client.matchOrganizationFromOrganizationCmekSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationExclusion', () => { - const fakePath = "/rendered/path/organizationExclusion"; - const expectedParameters = { - organization: "organizationValue", - exclusion: "exclusionValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationExclusionPath', () => { - const result = client.organizationExclusionPath("organizationValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationExclusionName', () => { - const result = client.matchOrganizationFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromOrganizationExclusionName', () => { - const result = client.matchExclusionFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucket', () => { - const fakePath = "/rendered/path/organizationLocationBucket"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketPath', () => { - const result = client.organizationLocationBucketPath("organizationValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketName', () => { - const result = client.matchLocationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketName', () => { - const result = client.matchBucketFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucketView', () => { - const fakePath = "/rendered/path/organizationLocationBucketView"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketViewPath', () => { - const result = client.organizationLocationBucketViewPath("organizationValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketViewName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketViewName', () => { - const result = client.matchLocationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketViewName', () => { - const result = client.matchBucketFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromOrganizationLocationBucketViewName', () => { - const result = client.matchViewFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLog', () => { - const fakePath = "/rendered/path/organizationLog"; - const expectedParameters = { - organization: "organizationValue", - log: "logValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLogPath', () => { - const result = client.organizationLogPath("organizationValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLogName', () => { - const result = client.matchOrganizationFromOrganizationLogName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromOrganizationLogName', () => { - const result = client.matchLogFromOrganizationLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSettings', () => { - const fakePath = "/rendered/path/organizationSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSettingsPath', () => { - const result = client.organizationSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSettingsName', () => { - const result = client.matchOrganizationFromOrganizationSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSink', () => { - const fakePath = "/rendered/path/organizationSink"; - const expectedParameters = { - organization: "organizationValue", - sink: "sinkValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSinkPath', () => { - const result = client.organizationSinkPath("organizationValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSinkName', () => { - const result = client.matchOrganizationFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromOrganizationSinkName', () => { - const result = client.matchSinkFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectCmekSettings', () => { - const fakePath = "/rendered/path/projectCmekSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectCmekSettingsPath', () => { - const result = client.projectCmekSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectCmekSettingsName', () => { - const result = client.matchProjectFromProjectCmekSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectExclusion', () => { - const fakePath = "/rendered/path/projectExclusion"; - const expectedParameters = { - project: "projectValue", - exclusion: "exclusionValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectExclusionPath', () => { - const result = client.projectExclusionPath("projectValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectExclusionName', () => { - const result = client.matchProjectFromProjectExclusionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromProjectExclusionName', () => { - const result = client.matchExclusionFromProjectExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucket', () => { - const fakePath = "/rendered/path/projectLocationBucket"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketPath', () => { - const result = client.projectLocationBucketPath("projectValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketName', () => { - const result = client.matchProjectFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketName', () => { - const result = client.matchLocationFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketName', () => { - const result = client.matchBucketFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucketView', () => { - const fakePath = "/rendered/path/projectLocationBucketView"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketViewPath', () => { - const result = client.projectLocationBucketViewPath("projectValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketViewName', () => { - const result = client.matchProjectFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketViewName', () => { - const result = client.matchLocationFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketViewName', () => { - const result = client.matchBucketFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromProjectLocationBucketViewName', () => { - const result = client.matchViewFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLog', () => { - const fakePath = "/rendered/path/projectLog"; - const expectedParameters = { - project: "projectValue", - log: "logValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLogPath', () => { - const result = client.projectLogPath("projectValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLogName', () => { - const result = client.matchProjectFromProjectLogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromProjectLogName', () => { - const result = client.matchLogFromProjectLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSettings', () => { - const fakePath = "/rendered/path/projectSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSettingsPath', () => { - const result = client.projectSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSettingsName', () => { - const result = client.matchProjectFromProjectSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSink', () => { - const fakePath = "/rendered/path/projectSink"; - const expectedParameters = { - project: "projectValue", - sink: "sinkValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSinkPath', () => { - const result = client.projectSinkPath("projectValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSinkName', () => { - const result = client.matchProjectFromProjectSinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromProjectSinkName', () => { - const result = client.matchSinkFromProjectSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_logging_service_v2_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_logging_service_v2_v2.ts.baseline deleted file mode 100644 index 2efb4ccb6716..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_logging_service_v2_v2.ts.baseline +++ /dev/null @@ -1,2272 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as loggingservicev2Module from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.LoggingServiceV2Client', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = loggingservicev2Module.v2.LoggingServiceV2Client.servicePath; - assert.strictEqual(servicePath, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = loggingservicev2Module.v2.LoggingServiceV2Client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new loggingservicev2Module.v2.LoggingServiceV2Client({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = loggingservicev2Module.v2.LoggingServiceV2Client.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.loggingServiceV2Stub, undefined); - await client.initialize(); - assert(client.loggingServiceV2Stub); - }); - - it('has close method for the initialized client', done => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.loggingServiceV2Stub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.loggingServiceV2Stub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - 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); - }); - }); - - describe('deleteLog', () => { - it('invokes deleteLog without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogRequest', ['logName']); - request.logName = defaultValue1; - const expectedHeaderRequestParams = `log_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteLog = stubSimpleCall(expectedResponse); - const [response] = await client.deleteLog(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLog without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogRequest', ['logName']); - request.logName = defaultValue1; - const expectedHeaderRequestParams = `log_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteLog = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteLog( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLog with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogRequest', ['logName']); - request.logName = defaultValue1; - const expectedHeaderRequestParams = `log_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteLog = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteLog(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLog with closed client', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogRequest', ['logName']); - request.logName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteLog(request), expectedError); - }); - }); - - describe('writeLogEntries', () => { - it('invokes writeLogEntries without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesResponse() - ); - client.innerApiCalls.writeLogEntries = stubSimpleCall(expectedResponse); - const [response] = await client.writeLogEntries(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes writeLogEntries without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesResponse() - ); - client.innerApiCalls.writeLogEntries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.writeLogEntries( - request, - (err?: Error|null, result?: protos.google.logging.v2.IWriteLogEntriesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes writeLogEntries with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.writeLogEntries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.writeLogEntries(request), expectedError); - }); - - it('invokes writeLogEntries with closed client', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.writeLogEntries(request), expectedError); - }); - }); - - describe('tailLogEntries', () => { - it('invokes tailLogEntries without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.TailLogEntriesRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.TailLogEntriesResponse() - ); - client.innerApiCalls.tailLogEntries = stubBidiStreamingCall(expectedResponse); - const stream = client.tailLogEntries(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.logging.v2.TailLogEntriesResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.tailLogEntries as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes tailLogEntries with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.TailLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.tailLogEntries = stubBidiStreamingCall(undefined, expectedError); - const stream = client.tailLogEntries(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.logging.v2.TailLogEntriesResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.tailLogEntries as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('listLogEntries', () => { - it('invokes listLogEntries without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - ]; - client.innerApiCalls.listLogEntries = stubSimpleCall(expectedResponse); - const [response] = await client.listLogEntries(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listLogEntries without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - ]; - client.innerApiCalls.listLogEntries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listLogEntries( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogEntry[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listLogEntries with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listLogEntries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listLogEntries(request), expectedError); - }); - - it('invokes listLogEntriesStream without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - ]; - client.descriptors.page.listLogEntries.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listLogEntriesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogEntry[] = []; - stream.on('data', (response: protos.google.logging.v2.LogEntry) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listLogEntries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogEntries, request)); - }); - - it('invokes listLogEntriesStream with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listLogEntries.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listLogEntriesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogEntry[] = []; - stream.on('data', (response: protos.google.logging.v2.LogEntry) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listLogEntries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogEntries, request)); - }); - - it('uses async iteration with listLogEntries without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - ]; - client.descriptors.page.listLogEntries.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogEntry[] = []; - const iterable = client.listLogEntriesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listLogEntries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listLogEntries with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listLogEntries.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLogEntriesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogEntry[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listLogEntries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listMonitoredResourceDescriptors', () => { - it('invokes listMonitoredResourceDescriptors without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCall(expectedResponse); - const [response] = await client.listMonitoredResourceDescriptors(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listMonitoredResourceDescriptors without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listMonitoredResourceDescriptors( - request, - (err?: Error|null, result?: protos.google.api.IMonitoredResourceDescriptor[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listMonitoredResourceDescriptors with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listMonitoredResourceDescriptors(request), expectedError); - }); - - it('invokes listMonitoredResourceDescriptorsStream without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.descriptors.page.listMonitoredResourceDescriptors.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listMonitoredResourceDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResourceDescriptor[] = []; - stream.on('data', (response: protos.google.api.MonitoredResourceDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMonitoredResourceDescriptors, request)); - }); - - it('invokes listMonitoredResourceDescriptorsStream with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listMonitoredResourceDescriptors.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listMonitoredResourceDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResourceDescriptor[] = []; - stream.on('data', (response: protos.google.api.MonitoredResourceDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMonitoredResourceDescriptors, request)); - }); - - it('uses async iteration with listMonitoredResourceDescriptors without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.api.IMonitoredResourceDescriptor[] = []; - const iterable = client.listMonitoredResourceDescriptorsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listMonitoredResourceDescriptors with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listMonitoredResourceDescriptorsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.api.IMonitoredResourceDescriptor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listLogs', () => { - it('invokes listLogs without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listLogs = stubSimpleCall(expectedResponse); - const [response] = await client.listLogs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogs without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listLogs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listLogs( - request, - (err?: Error|null, result?: string[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogs with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listLogs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listLogs(request), expectedError); - const actualRequest = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogsStream without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listLogs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listLogsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listLogs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogs, request)); - assert( - (client.descriptors.page.listLogs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listLogsStream with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listLogs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listLogsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listLogs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogs, request)); - assert( - (client.descriptors.page.listLogs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listLogs without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listLogs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: string[] = []; - const iterable = client.listLogsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listLogs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listLogs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listLogs with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listLogs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLogsAsync(request); - await assert.rejects(async () => { - const responses: string[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listLogs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listLogs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('billingAccountCmekSettings', () => { - const fakePath = "/rendered/path/billingAccountCmekSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountCmekSettingsPath', () => { - const result = client.billingAccountCmekSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountCmekSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountCmekSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountExclusion', () => { - const fakePath = "/rendered/path/billingAccountExclusion"; - const expectedParameters = { - billing_account: "billingAccountValue", - exclusion: "exclusionValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountExclusionPath', () => { - const result = client.billingAccountExclusionPath("billingAccountValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountExclusionName', () => { - const result = client.matchBillingAccountFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromBillingAccountExclusionName', () => { - const result = client.matchExclusionFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucket', () => { - const fakePath = "/rendered/path/billingAccountLocationBucket"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketPath', () => { - const result = client.billingAccountLocationBucketPath("billingAccountValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucketView', () => { - const fakePath = "/rendered/path/billingAccountLocationBucketView"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketViewPath', () => { - const result = client.billingAccountLocationBucketViewPath("billingAccountValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketViewName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromBillingAccountLocationBucketViewName', () => { - const result = client.matchViewFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLog', () => { - const fakePath = "/rendered/path/billingAccountLog"; - const expectedParameters = { - billing_account: "billingAccountValue", - log: "logValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLogPath', () => { - const result = client.billingAccountLogPath("billingAccountValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLogName', () => { - const result = client.matchBillingAccountFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromBillingAccountLogName', () => { - const result = client.matchLogFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSettings', () => { - const fakePath = "/rendered/path/billingAccountSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSettingsPath', () => { - const result = client.billingAccountSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSink', () => { - const fakePath = "/rendered/path/billingAccountSink"; - const expectedParameters = { - billing_account: "billingAccountValue", - sink: "sinkValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSinkPath', () => { - const result = client.billingAccountSinkPath("billingAccountValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSinkName', () => { - const result = client.matchBillingAccountFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromBillingAccountSinkName', () => { - const result = client.matchSinkFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderCmekSettings', () => { - const fakePath = "/rendered/path/folderCmekSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderCmekSettingsPath', () => { - const result = client.folderCmekSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderCmekSettingsName', () => { - const result = client.matchFolderFromFolderCmekSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderExclusion', () => { - const fakePath = "/rendered/path/folderExclusion"; - const expectedParameters = { - folder: "folderValue", - exclusion: "exclusionValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderExclusionPath', () => { - const result = client.folderExclusionPath("folderValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderExclusionName', () => { - const result = client.matchFolderFromFolderExclusionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromFolderExclusionName', () => { - const result = client.matchExclusionFromFolderExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucket', () => { - const fakePath = "/rendered/path/folderLocationBucket"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketPath', () => { - const result = client.folderLocationBucketPath("folderValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketName', () => { - const result = client.matchFolderFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketName', () => { - const result = client.matchLocationFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketName', () => { - const result = client.matchBucketFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucketView', () => { - const fakePath = "/rendered/path/folderLocationBucketView"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketViewPath', () => { - const result = client.folderLocationBucketViewPath("folderValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketViewName', () => { - const result = client.matchFolderFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketViewName', () => { - const result = client.matchLocationFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketViewName', () => { - const result = client.matchBucketFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromFolderLocationBucketViewName', () => { - const result = client.matchViewFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLog', () => { - const fakePath = "/rendered/path/folderLog"; - const expectedParameters = { - folder: "folderValue", - log: "logValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLogPath', () => { - const result = client.folderLogPath("folderValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLogName', () => { - const result = client.matchFolderFromFolderLogName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromFolderLogName', () => { - const result = client.matchLogFromFolderLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSettings', () => { - const fakePath = "/rendered/path/folderSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSettingsPath', () => { - const result = client.folderSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSettingsName', () => { - const result = client.matchFolderFromFolderSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSink', () => { - const fakePath = "/rendered/path/folderSink"; - const expectedParameters = { - folder: "folderValue", - sink: "sinkValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSinkPath', () => { - const result = client.folderSinkPath("folderValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSinkName', () => { - const result = client.matchFolderFromFolderSinkName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromFolderSinkName', () => { - const result = client.matchSinkFromFolderSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('logMetric', () => { - const fakePath = "/rendered/path/logMetric"; - const expectedParameters = { - project: "projectValue", - metric: "metricValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.logMetricPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.logMetricPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('logMetricPath', () => { - const result = client.logMetricPath("projectValue", "metricValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.logMetricPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLogMetricName', () => { - const result = client.matchProjectFromLogMetricName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricFromLogMetricName', () => { - const result = client.matchMetricFromLogMetricName(fakePath); - assert.strictEqual(result, "metricValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationCmekSettings', () => { - const fakePath = "/rendered/path/organizationCmekSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationCmekSettingsPath', () => { - const result = client.organizationCmekSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationCmekSettingsName', () => { - const result = client.matchOrganizationFromOrganizationCmekSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationExclusion', () => { - const fakePath = "/rendered/path/organizationExclusion"; - const expectedParameters = { - organization: "organizationValue", - exclusion: "exclusionValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationExclusionPath', () => { - const result = client.organizationExclusionPath("organizationValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationExclusionName', () => { - const result = client.matchOrganizationFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromOrganizationExclusionName', () => { - const result = client.matchExclusionFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucket', () => { - const fakePath = "/rendered/path/organizationLocationBucket"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketPath', () => { - const result = client.organizationLocationBucketPath("organizationValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketName', () => { - const result = client.matchLocationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketName', () => { - const result = client.matchBucketFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucketView', () => { - const fakePath = "/rendered/path/organizationLocationBucketView"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketViewPath', () => { - const result = client.organizationLocationBucketViewPath("organizationValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketViewName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketViewName', () => { - const result = client.matchLocationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketViewName', () => { - const result = client.matchBucketFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromOrganizationLocationBucketViewName', () => { - const result = client.matchViewFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLog', () => { - const fakePath = "/rendered/path/organizationLog"; - const expectedParameters = { - organization: "organizationValue", - log: "logValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLogPath', () => { - const result = client.organizationLogPath("organizationValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLogName', () => { - const result = client.matchOrganizationFromOrganizationLogName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromOrganizationLogName', () => { - const result = client.matchLogFromOrganizationLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSettings', () => { - const fakePath = "/rendered/path/organizationSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSettingsPath', () => { - const result = client.organizationSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSettingsName', () => { - const result = client.matchOrganizationFromOrganizationSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSink', () => { - const fakePath = "/rendered/path/organizationSink"; - const expectedParameters = { - organization: "organizationValue", - sink: "sinkValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSinkPath', () => { - const result = client.organizationSinkPath("organizationValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSinkName', () => { - const result = client.matchOrganizationFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromOrganizationSinkName', () => { - const result = client.matchSinkFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectCmekSettings', () => { - const fakePath = "/rendered/path/projectCmekSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectCmekSettingsPath', () => { - const result = client.projectCmekSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectCmekSettingsName', () => { - const result = client.matchProjectFromProjectCmekSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectExclusion', () => { - const fakePath = "/rendered/path/projectExclusion"; - const expectedParameters = { - project: "projectValue", - exclusion: "exclusionValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectExclusionPath', () => { - const result = client.projectExclusionPath("projectValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectExclusionName', () => { - const result = client.matchProjectFromProjectExclusionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromProjectExclusionName', () => { - const result = client.matchExclusionFromProjectExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucket', () => { - const fakePath = "/rendered/path/projectLocationBucket"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketPath', () => { - const result = client.projectLocationBucketPath("projectValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketName', () => { - const result = client.matchProjectFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketName', () => { - const result = client.matchLocationFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketName', () => { - const result = client.matchBucketFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucketView', () => { - const fakePath = "/rendered/path/projectLocationBucketView"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketViewPath', () => { - const result = client.projectLocationBucketViewPath("projectValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketViewName', () => { - const result = client.matchProjectFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketViewName', () => { - const result = client.matchLocationFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketViewName', () => { - const result = client.matchBucketFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromProjectLocationBucketViewName', () => { - const result = client.matchViewFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLog', () => { - const fakePath = "/rendered/path/projectLog"; - const expectedParameters = { - project: "projectValue", - log: "logValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLogPath', () => { - const result = client.projectLogPath("projectValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLogName', () => { - const result = client.matchProjectFromProjectLogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromProjectLogName', () => { - const result = client.matchLogFromProjectLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSettings', () => { - const fakePath = "/rendered/path/projectSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSettingsPath', () => { - const result = client.projectSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSettingsName', () => { - const result = client.matchProjectFromProjectSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSink', () => { - const fakePath = "/rendered/path/projectSink"; - const expectedParameters = { - project: "projectValue", - sink: "sinkValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSinkPath', () => { - const result = client.projectSinkPath("projectValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSinkName', () => { - const result = client.matchProjectFromProjectSinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromProjectSinkName', () => { - const result = client.matchSinkFromProjectSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_metrics_service_v2_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_metrics_service_v2_v2.ts.baseline deleted file mode 100644 index c03485d10852..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/esm/test/gapic_metrics_service_v2_v2.ts.baseline +++ /dev/null @@ -1,2114 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as metricsservicev2Module from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.MetricsServiceV2Client', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = metricsservicev2Module.v2.MetricsServiceV2Client.servicePath; - assert.strictEqual(servicePath, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = metricsservicev2Module.v2.MetricsServiceV2Client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new metricsservicev2Module.v2.MetricsServiceV2Client({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = metricsservicev2Module.v2.MetricsServiceV2Client.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.metricsServiceV2Stub, undefined); - await client.initialize(); - assert(client.metricsServiceV2Stub); - }); - - it('has close method for the initialized client', done => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.metricsServiceV2Stub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.metricsServiceV2Stub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - 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); - }); - }); - - describe('getLogMetric', () => { - it('invokes getLogMetric without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.getLogMetric = stubSimpleCall(expectedResponse); - const [response] = await client.getLogMetric(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLogMetric without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.getLogMetric = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getLogMetric( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogMetric|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLogMetric with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getLogMetric = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getLogMetric(request), expectedError); - const actualRequest = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLogMetric with closed client', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getLogMetric(request), expectedError); - }); - }); - - describe('createLogMetric', () => { - it('invokes createLogMetric without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateLogMetricRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.createLogMetric = stubSimpleCall(expectedResponse); - const [response] = await client.createLogMetric(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createLogMetric without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateLogMetricRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.createLogMetric = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createLogMetric( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogMetric|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createLogMetric with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateLogMetricRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createLogMetric = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createLogMetric(request), expectedError); - const actualRequest = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createLogMetric with closed client', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateLogMetricRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createLogMetric(request), expectedError); - }); - }); - - describe('updateLogMetric', () => { - it('invokes updateLogMetric without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.updateLogMetric = stubSimpleCall(expectedResponse); - const [response] = await client.updateLogMetric(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLogMetric without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.updateLogMetric = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateLogMetric( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogMetric|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLogMetric with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateLogMetric = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateLogMetric(request), expectedError); - const actualRequest = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLogMetric with closed client', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateLogMetric(request), expectedError); - }); - }); - - describe('deleteLogMetric', () => { - it('invokes deleteLogMetric without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteLogMetric = stubSimpleCall(expectedResponse); - const [response] = await client.deleteLogMetric(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLogMetric without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteLogMetric = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteLogMetric( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLogMetric with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteLogMetric = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteLogMetric(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLogMetric with closed client', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteLogMetric(request), expectedError); - }); - }); - - describe('listLogMetrics', () => { - it('invokes listLogMetrics without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - ]; - client.innerApiCalls.listLogMetrics = stubSimpleCall(expectedResponse); - const [response] = await client.listLogMetrics(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogMetrics without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - ]; - client.innerApiCalls.listLogMetrics = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listLogMetrics( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogMetric[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogMetrics with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listLogMetrics = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listLogMetrics(request), expectedError); - const actualRequest = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogMetricsStream without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - ]; - client.descriptors.page.listLogMetrics.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listLogMetricsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogMetric[] = []; - stream.on('data', (response: protos.google.logging.v2.LogMetric) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listLogMetrics.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogMetrics, request)); - assert( - (client.descriptors.page.listLogMetrics.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listLogMetricsStream with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listLogMetrics.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listLogMetricsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogMetric[] = []; - stream.on('data', (response: protos.google.logging.v2.LogMetric) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listLogMetrics.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogMetrics, request)); - assert( - (client.descriptors.page.listLogMetrics.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listLogMetrics without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - ]; - client.descriptors.page.listLogMetrics.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogMetric[] = []; - const iterable = client.listLogMetricsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listLogMetrics.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listLogMetrics.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listLogMetrics with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listLogMetrics.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLogMetricsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogMetric[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listLogMetrics.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listLogMetrics.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('billingAccountCmekSettings', () => { - const fakePath = "/rendered/path/billingAccountCmekSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountCmekSettingsPath', () => { - const result = client.billingAccountCmekSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountCmekSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountCmekSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountExclusion', () => { - const fakePath = "/rendered/path/billingAccountExclusion"; - const expectedParameters = { - billing_account: "billingAccountValue", - exclusion: "exclusionValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountExclusionPath', () => { - const result = client.billingAccountExclusionPath("billingAccountValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountExclusionName', () => { - const result = client.matchBillingAccountFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromBillingAccountExclusionName', () => { - const result = client.matchExclusionFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucket', () => { - const fakePath = "/rendered/path/billingAccountLocationBucket"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketPath', () => { - const result = client.billingAccountLocationBucketPath("billingAccountValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucketView', () => { - const fakePath = "/rendered/path/billingAccountLocationBucketView"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketViewPath', () => { - const result = client.billingAccountLocationBucketViewPath("billingAccountValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketViewName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromBillingAccountLocationBucketViewName', () => { - const result = client.matchViewFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLog', () => { - const fakePath = "/rendered/path/billingAccountLog"; - const expectedParameters = { - billing_account: "billingAccountValue", - log: "logValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLogPath', () => { - const result = client.billingAccountLogPath("billingAccountValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLogName', () => { - const result = client.matchBillingAccountFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromBillingAccountLogName', () => { - const result = client.matchLogFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSettings', () => { - const fakePath = "/rendered/path/billingAccountSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSettingsPath', () => { - const result = client.billingAccountSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSink', () => { - const fakePath = "/rendered/path/billingAccountSink"; - const expectedParameters = { - billing_account: "billingAccountValue", - sink: "sinkValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.billingAccountSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSinkPath', () => { - const result = client.billingAccountSinkPath("billingAccountValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSinkName', () => { - const result = client.matchBillingAccountFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromBillingAccountSinkName', () => { - const result = client.matchSinkFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderCmekSettings', () => { - const fakePath = "/rendered/path/folderCmekSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderCmekSettingsPath', () => { - const result = client.folderCmekSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderCmekSettingsName', () => { - const result = client.matchFolderFromFolderCmekSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderExclusion', () => { - const fakePath = "/rendered/path/folderExclusion"; - const expectedParameters = { - folder: "folderValue", - exclusion: "exclusionValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderExclusionPath', () => { - const result = client.folderExclusionPath("folderValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderExclusionName', () => { - const result = client.matchFolderFromFolderExclusionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromFolderExclusionName', () => { - const result = client.matchExclusionFromFolderExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucket', () => { - const fakePath = "/rendered/path/folderLocationBucket"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketPath', () => { - const result = client.folderLocationBucketPath("folderValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketName', () => { - const result = client.matchFolderFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketName', () => { - const result = client.matchLocationFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketName', () => { - const result = client.matchBucketFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucketView', () => { - const fakePath = "/rendered/path/folderLocationBucketView"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketViewPath', () => { - const result = client.folderLocationBucketViewPath("folderValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketViewName', () => { - const result = client.matchFolderFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketViewName', () => { - const result = client.matchLocationFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketViewName', () => { - const result = client.matchBucketFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromFolderLocationBucketViewName', () => { - const result = client.matchViewFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLog', () => { - const fakePath = "/rendered/path/folderLog"; - const expectedParameters = { - folder: "folderValue", - log: "logValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLogPath', () => { - const result = client.folderLogPath("folderValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLogName', () => { - const result = client.matchFolderFromFolderLogName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromFolderLogName', () => { - const result = client.matchLogFromFolderLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSettings', () => { - const fakePath = "/rendered/path/folderSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSettingsPath', () => { - const result = client.folderSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSettingsName', () => { - const result = client.matchFolderFromFolderSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSink', () => { - const fakePath = "/rendered/path/folderSink"; - const expectedParameters = { - folder: "folderValue", - sink: "sinkValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSinkPath', () => { - const result = client.folderSinkPath("folderValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSinkName', () => { - const result = client.matchFolderFromFolderSinkName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromFolderSinkName', () => { - const result = client.matchSinkFromFolderSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('logMetric', () => { - const fakePath = "/rendered/path/logMetric"; - const expectedParameters = { - project: "projectValue", - metric: "metricValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.logMetricPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.logMetricPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('logMetricPath', () => { - const result = client.logMetricPath("projectValue", "metricValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.logMetricPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLogMetricName', () => { - const result = client.matchProjectFromLogMetricName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricFromLogMetricName', () => { - const result = client.matchMetricFromLogMetricName(fakePath); - assert.strictEqual(result, "metricValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationCmekSettings', () => { - const fakePath = "/rendered/path/organizationCmekSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationCmekSettingsPath', () => { - const result = client.organizationCmekSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationCmekSettingsName', () => { - const result = client.matchOrganizationFromOrganizationCmekSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationExclusion', () => { - const fakePath = "/rendered/path/organizationExclusion"; - const expectedParameters = { - organization: "organizationValue", - exclusion: "exclusionValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationExclusionPath', () => { - const result = client.organizationExclusionPath("organizationValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationExclusionName', () => { - const result = client.matchOrganizationFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromOrganizationExclusionName', () => { - const result = client.matchExclusionFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucket', () => { - const fakePath = "/rendered/path/organizationLocationBucket"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketPath', () => { - const result = client.organizationLocationBucketPath("organizationValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketName', () => { - const result = client.matchLocationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketName', () => { - const result = client.matchBucketFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucketView', () => { - const fakePath = "/rendered/path/organizationLocationBucketView"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketViewPath', () => { - const result = client.organizationLocationBucketViewPath("organizationValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketViewName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketViewName', () => { - const result = client.matchLocationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketViewName', () => { - const result = client.matchBucketFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromOrganizationLocationBucketViewName', () => { - const result = client.matchViewFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLog', () => { - const fakePath = "/rendered/path/organizationLog"; - const expectedParameters = { - organization: "organizationValue", - log: "logValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLogPath', () => { - const result = client.organizationLogPath("organizationValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLogName', () => { - const result = client.matchOrganizationFromOrganizationLogName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromOrganizationLogName', () => { - const result = client.matchLogFromOrganizationLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSettings', () => { - const fakePath = "/rendered/path/organizationSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSettingsPath', () => { - const result = client.organizationSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSettingsName', () => { - const result = client.matchOrganizationFromOrganizationSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSink', () => { - const fakePath = "/rendered/path/organizationSink"; - const expectedParameters = { - organization: "organizationValue", - sink: "sinkValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSinkPath', () => { - const result = client.organizationSinkPath("organizationValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSinkName', () => { - const result = client.matchOrganizationFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromOrganizationSinkName', () => { - const result = client.matchSinkFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectCmekSettings', () => { - const fakePath = "/rendered/path/projectCmekSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectCmekSettingsPath', () => { - const result = client.projectCmekSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectCmekSettingsName', () => { - const result = client.matchProjectFromProjectCmekSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectExclusion', () => { - const fakePath = "/rendered/path/projectExclusion"; - const expectedParameters = { - project: "projectValue", - exclusion: "exclusionValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectExclusionPath', () => { - const result = client.projectExclusionPath("projectValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectExclusionName', () => { - const result = client.matchProjectFromProjectExclusionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromProjectExclusionName', () => { - const result = client.matchExclusionFromProjectExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucket', () => { - const fakePath = "/rendered/path/projectLocationBucket"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketPath', () => { - const result = client.projectLocationBucketPath("projectValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketName', () => { - const result = client.matchProjectFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketName', () => { - const result = client.matchLocationFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketName', () => { - const result = client.matchBucketFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucketView', () => { - const fakePath = "/rendered/path/projectLocationBucketView"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketViewPath', () => { - const result = client.projectLocationBucketViewPath("projectValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketViewName', () => { - const result = client.matchProjectFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketViewName', () => { - const result = client.matchLocationFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketViewName', () => { - const result = client.matchBucketFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromProjectLocationBucketViewName', () => { - const result = client.matchViewFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLog', () => { - const fakePath = "/rendered/path/projectLog"; - const expectedParameters = { - project: "projectValue", - log: "logValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLogPath', () => { - const result = client.projectLogPath("projectValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLogName', () => { - const result = client.matchProjectFromProjectLogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromProjectLogName', () => { - const result = client.matchLogFromProjectLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSettings', () => { - const fakePath = "/rendered/path/projectSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSettingsPath', () => { - const result = client.projectSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSettingsName', () => { - const result = client.matchProjectFromProjectSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSink', () => { - const fakePath = "/rendered/path/projectSink"; - const expectedParameters = { - project: "projectValue", - sink: "sinkValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSinkPath', () => { - const result = client.projectSinkPath("projectValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSinkName', () => { - const result = client.matchProjectFromProjectSinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromProjectSinkName', () => { - const result = client.matchSinkFromProjectSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/package.json b/core/generator/gapic-generator-typescript/baselines/logging-esm/package.json index 51e69ba5b936..28c8401407bc 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/logging-esm/package.json @@ -62,12 +62,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -82,21 +76,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/logging-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/logging-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/logging-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/logging-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/logging/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/logging/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/logging/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/logging/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/logging/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/logging/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/logging/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/logging/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/logging/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/logging/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/logging/package.json b/core/generator/gapic-generator-typescript/baselines/logging/package.json index 6b10e452bd2c..8ebd1fb9c735 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging/package.json +++ b/core/generator/gapic-generator-typescript/baselines/logging/package.json @@ -32,27 +32,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/logging/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/logging/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 1782c59b6c3f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const logging = require('logging'); - -function main() { - const configServiceV2Client = new logging.ConfigServiceV2Client(); - const loggingServiceV2Client = new logging.LoggingServiceV2Client(); - const metricsServiceV2Client = new logging.MetricsServiceV2Client(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/logging/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 4718840c897b..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {ConfigServiceV2Client, LoggingServiceV2Client, MetricsServiceV2Client} from 'logging'; - -// check that the client class type name can be used -function doStuffWithConfigServiceV2Client(client: ConfigServiceV2Client) { - client.close(); -} -function doStuffWithLoggingServiceV2Client(client: LoggingServiceV2Client) { - client.close(); -} -function doStuffWithMetricsServiceV2Client(client: MetricsServiceV2Client) { - client.close(); -} - -function main() { - // check that the client instance can be created - const configServiceV2Client = new ConfigServiceV2Client(); - doStuffWithConfigServiceV2Client(configServiceV2Client); - // check that the client instance can be created - const loggingServiceV2Client = new LoggingServiceV2Client(); - doStuffWithLoggingServiceV2Client(loggingServiceV2Client); - // check that the client instance can be created - const metricsServiceV2Client = new MetricsServiceV2Client(); - doStuffWithMetricsServiceV2Client(metricsServiceV2Client); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/logging/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_config_service_v2_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_config_service_v2_v2.ts.baseline deleted file mode 100644 index bde6151a8398..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_config_service_v2_v2.ts.baseline +++ /dev/null @@ -1,4844 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as configservicev2Module from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.ConfigServiceV2Client', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = configservicev2Module.v2.ConfigServiceV2Client.servicePath; - assert.strictEqual(servicePath, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = configservicev2Module.v2.ConfigServiceV2Client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new configservicev2Module.v2.ConfigServiceV2Client(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new configservicev2Module.v2.ConfigServiceV2Client({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new configservicev2Module.v2.ConfigServiceV2Client({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = configservicev2Module.v2.ConfigServiceV2Client.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.configServiceV2Stub, undefined); - await client.initialize(); - assert(client.configServiceV2Stub); - }); - - it('has close method for the initialized client', done => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.configServiceV2Stub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.configServiceV2Stub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - 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); - }); - }); - - describe('getBucket', () => { - it('invokes getBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.getBucket = stubSimpleCall(expectedResponse); - const [response] = await client.getBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.getBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBucket( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogBucket|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetBucketRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBucket(request), expectedError); - }); - }); - - describe('createBucket', () => { - it('invokes createBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateBucketRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.createBucket = stubSimpleCall(expectedResponse); - const [response] = await client.createBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateBucketRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.createBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBucket( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogBucket|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateBucketRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateBucketRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createBucket(request), expectedError); - }); - }); - - describe('updateBucket', () => { - it('invokes updateBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.updateBucket = stubSimpleCall(expectedResponse); - const [response] = await client.updateBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogBucket() - ); - client.innerApiCalls.updateBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBucket( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogBucket|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateBucketRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateBucket(request), expectedError); - }); - }); - - describe('deleteBucket', () => { - it('invokes deleteBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBucket = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBucket( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteBucket(request), expectedError); - }); - }); - - describe('undeleteBucket', () => { - it('invokes undeleteBucket without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UndeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UndeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.undeleteBucket = stubSimpleCall(expectedResponse); - const [response] = await client.undeleteBucket(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteBucket without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UndeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UndeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.undeleteBucket = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.undeleteBucket( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteBucket with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UndeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UndeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.undeleteBucket = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.undeleteBucket(request), expectedError); - const actualRequest = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.undeleteBucket as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes undeleteBucket with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UndeleteBucketRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UndeleteBucketRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.undeleteBucket(request), expectedError); - }); - }); - - describe('getView', () => { - it('invokes getView without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.getView = stubSimpleCall(expectedResponse); - const [response] = await client.getView(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getView without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.getView = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getView( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogView|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getView with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getView = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getView(request), expectedError); - const actualRequest = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getView with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetViewRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getView(request), expectedError); - }); - }); - - describe('createView', () => { - it('invokes createView without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateViewRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.createView = stubSimpleCall(expectedResponse); - const [response] = await client.createView(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createView without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateViewRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.createView = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createView( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogView|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createView with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateViewRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createView = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createView(request), expectedError); - const actualRequest = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createView with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateViewRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createView(request), expectedError); - }); - }); - - describe('updateView', () => { - it('invokes updateView without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.updateView = stubSimpleCall(expectedResponse); - const [response] = await client.updateView(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateView without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogView() - ); - client.innerApiCalls.updateView = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateView( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogView|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateView with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateView = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateView(request), expectedError); - const actualRequest = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateView with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateViewRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateView(request), expectedError); - }); - }); - - describe('deleteView', () => { - it('invokes deleteView without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteView = stubSimpleCall(expectedResponse); - const [response] = await client.deleteView(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteView without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteView = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteView( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteView with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteViewRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteView = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteView(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteView as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteView with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteViewRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteViewRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteView(request), expectedError); - }); - }); - - describe('getSink', () => { - it('invokes getSink without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.getSink = stubSimpleCall(expectedResponse); - const [response] = await client.getSink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSink without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.getSink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSink( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogSink|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSink with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSink(request), expectedError); - const actualRequest = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSink with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSink(request), expectedError); - }); - }); - - describe('createSink', () => { - it('invokes createSink without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateSinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.createSink = stubSimpleCall(expectedResponse); - const [response] = await client.createSink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSink without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateSinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.createSink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSink( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogSink|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSink with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateSinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createSink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSink(request), expectedError); - const actualRequest = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createSink with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateSinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSink(request), expectedError); - }); - }); - - describe('updateSink', () => { - it('invokes updateSink without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.updateSink = stubSimpleCall(expectedResponse); - const [response] = await client.updateSink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSink without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogSink() - ); - client.innerApiCalls.updateSink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateSink( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogSink|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSink with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateSink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateSink(request), expectedError); - const actualRequest = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSink with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateSink(request), expectedError); - }); - }); - - describe('deleteSink', () => { - it('invokes deleteSink without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSink = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSink without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSink( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSink with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedHeaderRequestParams = `sink_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSink(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSink with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteSinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteSinkRequest', ['sinkName']); - request.sinkName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteSink(request), expectedError); - }); - }); - - describe('getExclusion', () => { - it('invokes getExclusion without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.getExclusion = stubSimpleCall(expectedResponse); - const [response] = await client.getExclusion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getExclusion without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.getExclusion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getExclusion( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogExclusion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getExclusion with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getExclusion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getExclusion(request), expectedError); - const actualRequest = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getExclusion with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getExclusion(request), expectedError); - }); - }); - - describe('createExclusion', () => { - it('invokes createExclusion without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateExclusionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.createExclusion = stubSimpleCall(expectedResponse); - const [response] = await client.createExclusion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createExclusion without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateExclusionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.createExclusion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createExclusion( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogExclusion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createExclusion with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateExclusionRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createExclusion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createExclusion(request), expectedError); - const actualRequest = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createExclusion with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateExclusionRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createExclusion(request), expectedError); - }); - }); - - describe('updateExclusion', () => { - it('invokes updateExclusion without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.updateExclusion = stubSimpleCall(expectedResponse); - const [response] = await client.updateExclusion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateExclusion without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogExclusion() - ); - client.innerApiCalls.updateExclusion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateExclusion( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogExclusion|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateExclusion with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateExclusion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateExclusion(request), expectedError); - const actualRequest = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateExclusion with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateExclusion(request), expectedError); - }); - }); - - describe('deleteExclusion', () => { - it('invokes deleteExclusion without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteExclusion = stubSimpleCall(expectedResponse); - const [response] = await client.deleteExclusion(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteExclusion without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteExclusion = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteExclusion( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteExclusion with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteExclusion = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteExclusion(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteExclusion as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteExclusion with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteExclusionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteExclusionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteExclusion(request), expectedError); - }); - }); - - describe('getCmekSettings', () => { - it('invokes getCmekSettings without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.CmekSettings() - ); - client.innerApiCalls.getCmekSettings = stubSimpleCall(expectedResponse); - const [response] = await client.getCmekSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCmekSettings without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.CmekSettings() - ); - client.innerApiCalls.getCmekSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getCmekSettings( - request, - (err?: Error|null, result?: protos.google.logging.v2.ICmekSettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCmekSettings with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getCmekSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getCmekSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCmekSettings with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getCmekSettings(request), expectedError); - }); - }); - - describe('updateCmekSettings', () => { - it('invokes updateCmekSettings without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.CmekSettings() - ); - client.innerApiCalls.updateCmekSettings = stubSimpleCall(expectedResponse); - const [response] = await client.updateCmekSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCmekSettings without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.CmekSettings() - ); - client.innerApiCalls.updateCmekSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCmekSettings( - request, - (err?: Error|null, result?: protos.google.logging.v2.ICmekSettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCmekSettings with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCmekSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCmekSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCmekSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCmekSettings with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateCmekSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateCmekSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCmekSettings(request), expectedError); - }); - }); - - describe('getSettings', () => { - it('invokes getSettings without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.Settings() - ); - client.innerApiCalls.getSettings = stubSimpleCall(expectedResponse); - const [response] = await client.getSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSettings without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.Settings() - ); - client.innerApiCalls.getSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSettings( - request, - (err?: Error|null, result?: protos.google.logging.v2.ISettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSettings with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSettings with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSettings(request), expectedError); - }); - }); - - describe('updateSettings', () => { - it('invokes updateSettings without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.Settings() - ); - client.innerApiCalls.updateSettings = stubSimpleCall(expectedResponse); - const [response] = await client.updateSettings(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSettings without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.Settings() - ); - client.innerApiCalls.updateSettings = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateSettings( - request, - (err?: Error|null, result?: protos.google.logging.v2.ISettings|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSettings with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateSettings = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateSettings(request), expectedError); - const actualRequest = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateSettings as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateSettings with closed client', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateSettingsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateSettingsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateSettings(request), expectedError); - }); - }); - - describe('copyLogEntries', () => { - it('invokes copyLogEntries without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CopyLogEntriesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.copyLogEntries = stubLongRunningCall(expectedResponse); - const [operation] = await client.copyLogEntries(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes copyLogEntries without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CopyLogEntriesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.copyLogEntries = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.copyLogEntries( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes copyLogEntries with call error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CopyLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.copyLogEntries = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.copyLogEntries(request), expectedError); - }); - - it('invokes copyLogEntries with LRO error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CopyLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.copyLogEntries = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.copyLogEntries(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkCopyLogEntriesProgress without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCopyLogEntriesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCopyLogEntriesProgress with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCopyLogEntriesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listBuckets', () => { - it('invokes listBuckets without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - ]; - client.innerApiCalls.listBuckets = stubSimpleCall(expectedResponse); - const [response] = await client.listBuckets(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBuckets without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - ]; - client.innerApiCalls.listBuckets = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBuckets( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogBucket[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBuckets with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBuckets = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBuckets(request), expectedError); - const actualRequest = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBuckets as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBucketsStream without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - ]; - client.descriptors.page.listBuckets.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listBucketsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogBucket[] = []; - stream.on('data', (response: protos.google.logging.v2.LogBucket) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listBuckets.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBuckets, request)); - assert( - (client.descriptors.page.listBuckets.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listBucketsStream with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBuckets.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listBucketsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogBucket[] = []; - stream.on('data', (response: protos.google.logging.v2.LogBucket) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listBuckets.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBuckets, request)); - assert( - (client.descriptors.page.listBuckets.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBuckets without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - generateSampleMessage(new protos.google.logging.v2.LogBucket()), - ]; - client.descriptors.page.listBuckets.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogBucket[] = []; - const iterable = client.listBucketsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listBuckets.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBuckets.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBuckets with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListBucketsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListBucketsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBuckets.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBucketsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogBucket[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listBuckets.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBuckets.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listViews', () => { - it('invokes listViews without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - ]; - client.innerApiCalls.listViews = stubSimpleCall(expectedResponse); - const [response] = await client.listViews(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listViews without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - ]; - client.innerApiCalls.listViews = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listViews( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogView[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listViews with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listViews = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listViews(request), expectedError); - const actualRequest = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listViews as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listViewsStream without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - ]; - client.descriptors.page.listViews.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listViewsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogView[] = []; - stream.on('data', (response: protos.google.logging.v2.LogView) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listViews.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listViews, request)); - assert( - (client.descriptors.page.listViews.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listViewsStream with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listViews.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listViewsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogView[] = []; - stream.on('data', (response: protos.google.logging.v2.LogView) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listViews.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listViews, request)); - assert( - (client.descriptors.page.listViews.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listViews without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - generateSampleMessage(new protos.google.logging.v2.LogView()), - ]; - client.descriptors.page.listViews.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogView[] = []; - const iterable = client.listViewsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listViews.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listViews.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listViews with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListViewsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListViewsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listViews.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listViewsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogView[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listViews.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listViews.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listSinks', () => { - it('invokes listSinks without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - ]; - client.innerApiCalls.listSinks = stubSimpleCall(expectedResponse); - const [response] = await client.listSinks(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSinks without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - ]; - client.innerApiCalls.listSinks = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSinks( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogSink[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSinks with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listSinks = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSinks(request), expectedError); - const actualRequest = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listSinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listSinksStream without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - ]; - client.descriptors.page.listSinks.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSinksStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogSink[] = []; - stream.on('data', (response: protos.google.logging.v2.LogSink) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listSinks.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSinks, request)); - assert( - (client.descriptors.page.listSinks.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listSinksStream with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listSinks.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSinksStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogSink[] = []; - stream.on('data', (response: protos.google.logging.v2.LogSink) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSinks.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSinks, request)); - assert( - (client.descriptors.page.listSinks.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSinks without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - generateSampleMessage(new protos.google.logging.v2.LogSink()), - ]; - client.descriptors.page.listSinks.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogSink[] = []; - const iterable = client.listSinksAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSinks.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSinks.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listSinks with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListSinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListSinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listSinks.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSinksAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogSink[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSinks.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listSinks.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listExclusions', () => { - it('invokes listExclusions without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - ]; - client.innerApiCalls.listExclusions = stubSimpleCall(expectedResponse); - const [response] = await client.listExclusions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listExclusions without error using callback', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - ]; - client.innerApiCalls.listExclusions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listExclusions( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogExclusion[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listExclusions with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listExclusions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listExclusions(request), expectedError); - const actualRequest = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listExclusions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listExclusionsStream without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - ]; - client.descriptors.page.listExclusions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listExclusionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogExclusion[] = []; - stream.on('data', (response: protos.google.logging.v2.LogExclusion) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listExclusions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listExclusions, request)); - assert( - (client.descriptors.page.listExclusions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listExclusionsStream with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listExclusions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listExclusionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogExclusion[] = []; - stream.on('data', (response: protos.google.logging.v2.LogExclusion) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listExclusions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listExclusions, request)); - assert( - (client.descriptors.page.listExclusions.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listExclusions without error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - generateSampleMessage(new protos.google.logging.v2.LogExclusion()), - ]; - client.descriptors.page.listExclusions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogExclusion[] = []; - const iterable = client.listExclusionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listExclusions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listExclusions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listExclusions with error', async () => { - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListExclusionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListExclusionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listExclusions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listExclusionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogExclusion[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listExclusions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listExclusions.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('billingAccountCmekSettings', async () => { - const fakePath = "/rendered/path/billingAccountCmekSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountCmekSettingsPath', () => { - const result = client.billingAccountCmekSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountCmekSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountCmekSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountExclusion', async () => { - const fakePath = "/rendered/path/billingAccountExclusion"; - const expectedParameters = { - billing_account: "billingAccountValue", - exclusion: "exclusionValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountExclusionPath', () => { - const result = client.billingAccountExclusionPath("billingAccountValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountExclusionName', () => { - const result = client.matchBillingAccountFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromBillingAccountExclusionName', () => { - const result = client.matchExclusionFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucket', async () => { - const fakePath = "/rendered/path/billingAccountLocationBucket"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketPath', () => { - const result = client.billingAccountLocationBucketPath("billingAccountValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucketView', async () => { - const fakePath = "/rendered/path/billingAccountLocationBucketView"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketViewPath', () => { - const result = client.billingAccountLocationBucketViewPath("billingAccountValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketViewName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromBillingAccountLocationBucketViewName', () => { - const result = client.matchViewFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLog', async () => { - const fakePath = "/rendered/path/billingAccountLog"; - const expectedParameters = { - billing_account: "billingAccountValue", - log: "logValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLogPath', () => { - const result = client.billingAccountLogPath("billingAccountValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLogName', () => { - const result = client.matchBillingAccountFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromBillingAccountLogName', () => { - const result = client.matchLogFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSettings', async () => { - const fakePath = "/rendered/path/billingAccountSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSettingsPath', () => { - const result = client.billingAccountSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSink', async () => { - const fakePath = "/rendered/path/billingAccountSink"; - const expectedParameters = { - billing_account: "billingAccountValue", - sink: "sinkValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSinkPath', () => { - const result = client.billingAccountSinkPath("billingAccountValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSinkName', () => { - const result = client.matchBillingAccountFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromBillingAccountSinkName', () => { - const result = client.matchSinkFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderCmekSettings', async () => { - const fakePath = "/rendered/path/folderCmekSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderCmekSettingsPath', () => { - const result = client.folderCmekSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderCmekSettingsName', () => { - const result = client.matchFolderFromFolderCmekSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderExclusion', async () => { - const fakePath = "/rendered/path/folderExclusion"; - const expectedParameters = { - folder: "folderValue", - exclusion: "exclusionValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderExclusionPath', () => { - const result = client.folderExclusionPath("folderValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderExclusionName', () => { - const result = client.matchFolderFromFolderExclusionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromFolderExclusionName', () => { - const result = client.matchExclusionFromFolderExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucket', async () => { - const fakePath = "/rendered/path/folderLocationBucket"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketPath', () => { - const result = client.folderLocationBucketPath("folderValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketName', () => { - const result = client.matchFolderFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketName', () => { - const result = client.matchLocationFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketName', () => { - const result = client.matchBucketFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucketView', async () => { - const fakePath = "/rendered/path/folderLocationBucketView"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketViewPath', () => { - const result = client.folderLocationBucketViewPath("folderValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketViewName', () => { - const result = client.matchFolderFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketViewName', () => { - const result = client.matchLocationFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketViewName', () => { - const result = client.matchBucketFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromFolderLocationBucketViewName', () => { - const result = client.matchViewFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLog', async () => { - const fakePath = "/rendered/path/folderLog"; - const expectedParameters = { - folder: "folderValue", - log: "logValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLogPath', () => { - const result = client.folderLogPath("folderValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLogName', () => { - const result = client.matchFolderFromFolderLogName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromFolderLogName', () => { - const result = client.matchLogFromFolderLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSettings', async () => { - const fakePath = "/rendered/path/folderSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSettingsPath', () => { - const result = client.folderSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSettingsName', () => { - const result = client.matchFolderFromFolderSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSink', async () => { - const fakePath = "/rendered/path/folderSink"; - const expectedParameters = { - folder: "folderValue", - sink: "sinkValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSinkPath', () => { - const result = client.folderSinkPath("folderValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSinkName', () => { - const result = client.matchFolderFromFolderSinkName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromFolderSinkName', () => { - const result = client.matchSinkFromFolderSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('location', async () => { - const fakePath = "/rendered/path/location"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.locationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.locationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath("projectValue", "locationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('logMetric', async () => { - const fakePath = "/rendered/path/logMetric"; - const expectedParameters = { - project: "projectValue", - metric: "metricValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.logMetricPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.logMetricPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('logMetricPath', () => { - const result = client.logMetricPath("projectValue", "metricValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.logMetricPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLogMetricName', () => { - const result = client.matchProjectFromLogMetricName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricFromLogMetricName', () => { - const result = client.matchMetricFromLogMetricName(fakePath); - assert.strictEqual(result, "metricValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationCmekSettings', async () => { - const fakePath = "/rendered/path/organizationCmekSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationCmekSettingsPath', () => { - const result = client.organizationCmekSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationCmekSettingsName', () => { - const result = client.matchOrganizationFromOrganizationCmekSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationExclusion', async () => { - const fakePath = "/rendered/path/organizationExclusion"; - const expectedParameters = { - organization: "organizationValue", - exclusion: "exclusionValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationExclusionPath', () => { - const result = client.organizationExclusionPath("organizationValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationExclusionName', () => { - const result = client.matchOrganizationFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromOrganizationExclusionName', () => { - const result = client.matchExclusionFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucket', async () => { - const fakePath = "/rendered/path/organizationLocationBucket"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketPath', () => { - const result = client.organizationLocationBucketPath("organizationValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketName', () => { - const result = client.matchLocationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketName', () => { - const result = client.matchBucketFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucketView', async () => { - const fakePath = "/rendered/path/organizationLocationBucketView"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketViewPath', () => { - const result = client.organizationLocationBucketViewPath("organizationValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketViewName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketViewName', () => { - const result = client.matchLocationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketViewName', () => { - const result = client.matchBucketFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromOrganizationLocationBucketViewName', () => { - const result = client.matchViewFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLog', async () => { - const fakePath = "/rendered/path/organizationLog"; - const expectedParameters = { - organization: "organizationValue", - log: "logValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLogPath', () => { - const result = client.organizationLogPath("organizationValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLogName', () => { - const result = client.matchOrganizationFromOrganizationLogName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromOrganizationLogName', () => { - const result = client.matchLogFromOrganizationLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSettings', async () => { - const fakePath = "/rendered/path/organizationSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSettingsPath', () => { - const result = client.organizationSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSettingsName', () => { - const result = client.matchOrganizationFromOrganizationSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSink', async () => { - const fakePath = "/rendered/path/organizationSink"; - const expectedParameters = { - organization: "organizationValue", - sink: "sinkValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSinkPath', () => { - const result = client.organizationSinkPath("organizationValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSinkName', () => { - const result = client.matchOrganizationFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromOrganizationSinkName', () => { - const result = client.matchSinkFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectCmekSettings', async () => { - const fakePath = "/rendered/path/projectCmekSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectCmekSettingsPath', () => { - const result = client.projectCmekSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectCmekSettingsName', () => { - const result = client.matchProjectFromProjectCmekSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectExclusion', async () => { - const fakePath = "/rendered/path/projectExclusion"; - const expectedParameters = { - project: "projectValue", - exclusion: "exclusionValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectExclusionPath', () => { - const result = client.projectExclusionPath("projectValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectExclusionName', () => { - const result = client.matchProjectFromProjectExclusionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromProjectExclusionName', () => { - const result = client.matchExclusionFromProjectExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucket', async () => { - const fakePath = "/rendered/path/projectLocationBucket"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketPath', () => { - const result = client.projectLocationBucketPath("projectValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketName', () => { - const result = client.matchProjectFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketName', () => { - const result = client.matchLocationFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketName', () => { - const result = client.matchBucketFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucketView', async () => { - const fakePath = "/rendered/path/projectLocationBucketView"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketViewPath', () => { - const result = client.projectLocationBucketViewPath("projectValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketViewName', () => { - const result = client.matchProjectFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketViewName', () => { - const result = client.matchLocationFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketViewName', () => { - const result = client.matchBucketFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromProjectLocationBucketViewName', () => { - const result = client.matchViewFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLog', async () => { - const fakePath = "/rendered/path/projectLog"; - const expectedParameters = { - project: "projectValue", - log: "logValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLogPath', () => { - const result = client.projectLogPath("projectValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLogName', () => { - const result = client.matchProjectFromProjectLogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromProjectLogName', () => { - const result = client.matchLogFromProjectLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSettings', async () => { - const fakePath = "/rendered/path/projectSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSettingsPath', () => { - const result = client.projectSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSettingsName', () => { - const result = client.matchProjectFromProjectSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSink', async () => { - const fakePath = "/rendered/path/projectSink"; - const expectedParameters = { - project: "projectValue", - sink: "sinkValue", - }; - const client = new configservicev2Module.v2.ConfigServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSinkPath', () => { - const result = client.projectSinkPath("projectValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSinkName', () => { - const result = client.matchProjectFromProjectSinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromProjectSinkName', () => { - const result = client.matchSinkFromProjectSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_logging_service_v2_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_logging_service_v2_v2.ts.baseline deleted file mode 100644 index 12256c5f1e8b..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_logging_service_v2_v2.ts.baseline +++ /dev/null @@ -1,2263 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as loggingservicev2Module from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.LoggingServiceV2Client', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = loggingservicev2Module.v2.LoggingServiceV2Client.servicePath; - assert.strictEqual(servicePath, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = loggingservicev2Module.v2.LoggingServiceV2Client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new loggingservicev2Module.v2.LoggingServiceV2Client({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = loggingservicev2Module.v2.LoggingServiceV2Client.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.loggingServiceV2Stub, undefined); - await client.initialize(); - assert(client.loggingServiceV2Stub); - }); - - it('has close method for the initialized client', done => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.loggingServiceV2Stub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.loggingServiceV2Stub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - 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); - }); - }); - - describe('deleteLog', () => { - it('invokes deleteLog without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogRequest', ['logName']); - request.logName = defaultValue1; - const expectedHeaderRequestParams = `log_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteLog = stubSimpleCall(expectedResponse); - const [response] = await client.deleteLog(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLog without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogRequest', ['logName']); - request.logName = defaultValue1; - const expectedHeaderRequestParams = `log_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteLog = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteLog( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLog with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogRequest', ['logName']); - request.logName = defaultValue1; - const expectedHeaderRequestParams = `log_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteLog = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteLog(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLog with closed client', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogRequest', ['logName']); - request.logName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteLog(request), expectedError); - }); - }); - - describe('writeLogEntries', () => { - it('invokes writeLogEntries without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesResponse() - ); - client.innerApiCalls.writeLogEntries = stubSimpleCall(expectedResponse); - const [response] = await client.writeLogEntries(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes writeLogEntries without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesResponse() - ); - client.innerApiCalls.writeLogEntries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.writeLogEntries( - request, - (err?: Error|null, result?: protos.google.logging.v2.IWriteLogEntriesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes writeLogEntries with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.writeLogEntries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.writeLogEntries(request), expectedError); - }); - - it('invokes writeLogEntries with closed client', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.WriteLogEntriesRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.writeLogEntries(request), expectedError); - }); - }); - - describe('tailLogEntries', () => { - it('invokes tailLogEntries without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.TailLogEntriesRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.TailLogEntriesResponse() - ); - client.innerApiCalls.tailLogEntries = stubBidiStreamingCall(expectedResponse); - const stream = client.tailLogEntries(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.logging.v2.TailLogEntriesResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.tailLogEntries as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes tailLogEntries with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.TailLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.tailLogEntries = stubBidiStreamingCall(undefined, expectedError); - const stream = client.tailLogEntries(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.logging.v2.TailLogEntriesResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.tailLogEntries as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('listLogEntries', () => { - it('invokes listLogEntries without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - ]; - client.innerApiCalls.listLogEntries = stubSimpleCall(expectedResponse); - const [response] = await client.listLogEntries(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listLogEntries without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - ]; - client.innerApiCalls.listLogEntries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listLogEntries( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogEntry[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listLogEntries with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listLogEntries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listLogEntries(request), expectedError); - }); - - it('invokes listLogEntriesStream without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - ]; - client.descriptors.page.listLogEntries.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listLogEntriesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogEntry[] = []; - stream.on('data', (response: protos.google.logging.v2.LogEntry) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listLogEntries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogEntries, request)); - }); - - it('invokes listLogEntriesStream with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listLogEntries.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listLogEntriesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogEntry[] = []; - stream.on('data', (response: protos.google.logging.v2.LogEntry) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listLogEntries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogEntries, request)); - }); - - it('uses async iteration with listLogEntries without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - generateSampleMessage(new protos.google.logging.v2.LogEntry()), - ]; - client.descriptors.page.listLogEntries.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogEntry[] = []; - const iterable = client.listLogEntriesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listLogEntries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listLogEntries with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogEntriesRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listLogEntries.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLogEntriesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogEntry[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listLogEntries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listMonitoredResourceDescriptors', () => { - it('invokes listMonitoredResourceDescriptors without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCall(expectedResponse); - const [response] = await client.listMonitoredResourceDescriptors(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listMonitoredResourceDescriptors without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listMonitoredResourceDescriptors( - request, - (err?: Error|null, result?: protos.google.api.IMonitoredResourceDescriptor[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listMonitoredResourceDescriptors with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listMonitoredResourceDescriptors(request), expectedError); - }); - - it('invokes listMonitoredResourceDescriptorsStream without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.descriptors.page.listMonitoredResourceDescriptors.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listMonitoredResourceDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResourceDescriptor[] = []; - stream.on('data', (response: protos.google.api.MonitoredResourceDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMonitoredResourceDescriptors, request)); - }); - - it('invokes listMonitoredResourceDescriptorsStream with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listMonitoredResourceDescriptors.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listMonitoredResourceDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResourceDescriptor[] = []; - stream.on('data', (response: protos.google.api.MonitoredResourceDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMonitoredResourceDescriptors, request)); - }); - - it('uses async iteration with listMonitoredResourceDescriptors without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.api.IMonitoredResourceDescriptor[] = []; - const iterable = client.listMonitoredResourceDescriptorsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listMonitoredResourceDescriptors with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListMonitoredResourceDescriptorsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listMonitoredResourceDescriptorsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.api.IMonitoredResourceDescriptor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listLogs', () => { - it('invokes listLogs without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listLogs = stubSimpleCall(expectedResponse); - const [response] = await client.listLogs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogs without error using callback', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listLogs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listLogs( - request, - (err?: Error|null, result?: string[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogs with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listLogs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listLogs(request), expectedError); - const actualRequest = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogsStream without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listLogs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listLogsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listLogs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogs, request)); - assert( - (client.descriptors.page.listLogs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listLogsStream with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listLogs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listLogsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: string[] = []; - stream.on('data', (response: string) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listLogs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogs, request)); - assert( - (client.descriptors.page.listLogs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listLogs without error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listLogs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: string[] = []; - const iterable = client.listLogsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listLogs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listLogs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listLogs with error', async () => { - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listLogs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLogsAsync(request); - await assert.rejects(async () => { - const responses: string[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listLogs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listLogs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('billingAccountCmekSettings', async () => { - const fakePath = "/rendered/path/billingAccountCmekSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountCmekSettingsPath', () => { - const result = client.billingAccountCmekSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountCmekSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountCmekSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountExclusion', async () => { - const fakePath = "/rendered/path/billingAccountExclusion"; - const expectedParameters = { - billing_account: "billingAccountValue", - exclusion: "exclusionValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountExclusionPath', () => { - const result = client.billingAccountExclusionPath("billingAccountValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountExclusionName', () => { - const result = client.matchBillingAccountFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromBillingAccountExclusionName', () => { - const result = client.matchExclusionFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucket', async () => { - const fakePath = "/rendered/path/billingAccountLocationBucket"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketPath', () => { - const result = client.billingAccountLocationBucketPath("billingAccountValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucketView', async () => { - const fakePath = "/rendered/path/billingAccountLocationBucketView"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketViewPath', () => { - const result = client.billingAccountLocationBucketViewPath("billingAccountValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketViewName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromBillingAccountLocationBucketViewName', () => { - const result = client.matchViewFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLog', async () => { - const fakePath = "/rendered/path/billingAccountLog"; - const expectedParameters = { - billing_account: "billingAccountValue", - log: "logValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLogPath', () => { - const result = client.billingAccountLogPath("billingAccountValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLogName', () => { - const result = client.matchBillingAccountFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromBillingAccountLogName', () => { - const result = client.matchLogFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSettings', async () => { - const fakePath = "/rendered/path/billingAccountSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSettingsPath', () => { - const result = client.billingAccountSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSink', async () => { - const fakePath = "/rendered/path/billingAccountSink"; - const expectedParameters = { - billing_account: "billingAccountValue", - sink: "sinkValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSinkPath', () => { - const result = client.billingAccountSinkPath("billingAccountValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSinkName', () => { - const result = client.matchBillingAccountFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromBillingAccountSinkName', () => { - const result = client.matchSinkFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderCmekSettings', async () => { - const fakePath = "/rendered/path/folderCmekSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderCmekSettingsPath', () => { - const result = client.folderCmekSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderCmekSettingsName', () => { - const result = client.matchFolderFromFolderCmekSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderExclusion', async () => { - const fakePath = "/rendered/path/folderExclusion"; - const expectedParameters = { - folder: "folderValue", - exclusion: "exclusionValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderExclusionPath', () => { - const result = client.folderExclusionPath("folderValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderExclusionName', () => { - const result = client.matchFolderFromFolderExclusionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromFolderExclusionName', () => { - const result = client.matchExclusionFromFolderExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucket', async () => { - const fakePath = "/rendered/path/folderLocationBucket"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketPath', () => { - const result = client.folderLocationBucketPath("folderValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketName', () => { - const result = client.matchFolderFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketName', () => { - const result = client.matchLocationFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketName', () => { - const result = client.matchBucketFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucketView', async () => { - const fakePath = "/rendered/path/folderLocationBucketView"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketViewPath', () => { - const result = client.folderLocationBucketViewPath("folderValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketViewName', () => { - const result = client.matchFolderFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketViewName', () => { - const result = client.matchLocationFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketViewName', () => { - const result = client.matchBucketFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromFolderLocationBucketViewName', () => { - const result = client.matchViewFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLog', async () => { - const fakePath = "/rendered/path/folderLog"; - const expectedParameters = { - folder: "folderValue", - log: "logValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLogPath', () => { - const result = client.folderLogPath("folderValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLogName', () => { - const result = client.matchFolderFromFolderLogName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromFolderLogName', () => { - const result = client.matchLogFromFolderLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSettings', async () => { - const fakePath = "/rendered/path/folderSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSettingsPath', () => { - const result = client.folderSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSettingsName', () => { - const result = client.matchFolderFromFolderSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSink', async () => { - const fakePath = "/rendered/path/folderSink"; - const expectedParameters = { - folder: "folderValue", - sink: "sinkValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSinkPath', () => { - const result = client.folderSinkPath("folderValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSinkName', () => { - const result = client.matchFolderFromFolderSinkName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromFolderSinkName', () => { - const result = client.matchSinkFromFolderSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('logMetric', async () => { - const fakePath = "/rendered/path/logMetric"; - const expectedParameters = { - project: "projectValue", - metric: "metricValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.logMetricPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.logMetricPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('logMetricPath', () => { - const result = client.logMetricPath("projectValue", "metricValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.logMetricPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLogMetricName', () => { - const result = client.matchProjectFromLogMetricName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricFromLogMetricName', () => { - const result = client.matchMetricFromLogMetricName(fakePath); - assert.strictEqual(result, "metricValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationCmekSettings', async () => { - const fakePath = "/rendered/path/organizationCmekSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationCmekSettingsPath', () => { - const result = client.organizationCmekSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationCmekSettingsName', () => { - const result = client.matchOrganizationFromOrganizationCmekSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationExclusion', async () => { - const fakePath = "/rendered/path/organizationExclusion"; - const expectedParameters = { - organization: "organizationValue", - exclusion: "exclusionValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationExclusionPath', () => { - const result = client.organizationExclusionPath("organizationValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationExclusionName', () => { - const result = client.matchOrganizationFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromOrganizationExclusionName', () => { - const result = client.matchExclusionFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucket', async () => { - const fakePath = "/rendered/path/organizationLocationBucket"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketPath', () => { - const result = client.organizationLocationBucketPath("organizationValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketName', () => { - const result = client.matchLocationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketName', () => { - const result = client.matchBucketFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucketView', async () => { - const fakePath = "/rendered/path/organizationLocationBucketView"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketViewPath', () => { - const result = client.organizationLocationBucketViewPath("organizationValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketViewName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketViewName', () => { - const result = client.matchLocationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketViewName', () => { - const result = client.matchBucketFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromOrganizationLocationBucketViewName', () => { - const result = client.matchViewFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLog', async () => { - const fakePath = "/rendered/path/organizationLog"; - const expectedParameters = { - organization: "organizationValue", - log: "logValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLogPath', () => { - const result = client.organizationLogPath("organizationValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLogName', () => { - const result = client.matchOrganizationFromOrganizationLogName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromOrganizationLogName', () => { - const result = client.matchLogFromOrganizationLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSettings', async () => { - const fakePath = "/rendered/path/organizationSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSettingsPath', () => { - const result = client.organizationSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSettingsName', () => { - const result = client.matchOrganizationFromOrganizationSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSink', async () => { - const fakePath = "/rendered/path/organizationSink"; - const expectedParameters = { - organization: "organizationValue", - sink: "sinkValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSinkPath', () => { - const result = client.organizationSinkPath("organizationValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSinkName', () => { - const result = client.matchOrganizationFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromOrganizationSinkName', () => { - const result = client.matchSinkFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectCmekSettings', async () => { - const fakePath = "/rendered/path/projectCmekSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectCmekSettingsPath', () => { - const result = client.projectCmekSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectCmekSettingsName', () => { - const result = client.matchProjectFromProjectCmekSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectExclusion', async () => { - const fakePath = "/rendered/path/projectExclusion"; - const expectedParameters = { - project: "projectValue", - exclusion: "exclusionValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectExclusionPath', () => { - const result = client.projectExclusionPath("projectValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectExclusionName', () => { - const result = client.matchProjectFromProjectExclusionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromProjectExclusionName', () => { - const result = client.matchExclusionFromProjectExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucket', async () => { - const fakePath = "/rendered/path/projectLocationBucket"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketPath', () => { - const result = client.projectLocationBucketPath("projectValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketName', () => { - const result = client.matchProjectFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketName', () => { - const result = client.matchLocationFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketName', () => { - const result = client.matchBucketFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucketView', async () => { - const fakePath = "/rendered/path/projectLocationBucketView"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketViewPath', () => { - const result = client.projectLocationBucketViewPath("projectValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketViewName', () => { - const result = client.matchProjectFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketViewName', () => { - const result = client.matchLocationFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketViewName', () => { - const result = client.matchBucketFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromProjectLocationBucketViewName', () => { - const result = client.matchViewFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLog', async () => { - const fakePath = "/rendered/path/projectLog"; - const expectedParameters = { - project: "projectValue", - log: "logValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLogPath', () => { - const result = client.projectLogPath("projectValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLogName', () => { - const result = client.matchProjectFromProjectLogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromProjectLogName', () => { - const result = client.matchLogFromProjectLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSettings', async () => { - const fakePath = "/rendered/path/projectSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSettingsPath', () => { - const result = client.projectSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSettingsName', () => { - const result = client.matchProjectFromProjectSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSink', async () => { - const fakePath = "/rendered/path/projectSink"; - const expectedParameters = { - project: "projectValue", - sink: "sinkValue", - }; - const client = new loggingservicev2Module.v2.LoggingServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSinkPath', () => { - const result = client.projectSinkPath("projectValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSinkName', () => { - const result = client.matchProjectFromProjectSinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromProjectSinkName', () => { - const result = client.matchSinkFromProjectSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_metrics_service_v2_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_metrics_service_v2_v2.ts.baseline deleted file mode 100644 index 42c74d03e950..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/logging/test/gapic_metrics_service_v2_v2.ts.baseline +++ /dev/null @@ -1,2105 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as metricsservicev2Module from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.MetricsServiceV2Client', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = metricsservicev2Module.v2.MetricsServiceV2Client.servicePath; - assert.strictEqual(servicePath, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = metricsservicev2Module.v2.MetricsServiceV2Client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'logging.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'logging.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new metricsservicev2Module.v2.MetricsServiceV2Client({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = metricsservicev2Module.v2.MetricsServiceV2Client.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.metricsServiceV2Stub, undefined); - await client.initialize(); - assert(client.metricsServiceV2Stub); - }); - - it('has close method for the initialized client', done => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.metricsServiceV2Stub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.metricsServiceV2Stub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - 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); - }); - }); - - describe('getLogMetric', () => { - it('invokes getLogMetric without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.getLogMetric = stubSimpleCall(expectedResponse); - const [response] = await client.getLogMetric(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLogMetric without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.getLogMetric = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getLogMetric( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogMetric|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLogMetric with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getLogMetric = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getLogMetric(request), expectedError); - const actualRequest = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLogMetric with closed client', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.GetLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.GetLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getLogMetric(request), expectedError); - }); - }); - - describe('createLogMetric', () => { - it('invokes createLogMetric without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateLogMetricRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.createLogMetric = stubSimpleCall(expectedResponse); - const [response] = await client.createLogMetric(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createLogMetric without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateLogMetricRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.createLogMetric = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createLogMetric( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogMetric|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createLogMetric with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateLogMetricRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createLogMetric = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createLogMetric(request), expectedError); - const actualRequest = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createLogMetric with closed client', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.CreateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.CreateLogMetricRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createLogMetric(request), expectedError); - }); - }); - - describe('updateLogMetric', () => { - it('invokes updateLogMetric without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.updateLogMetric = stubSimpleCall(expectedResponse); - const [response] = await client.updateLogMetric(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLogMetric without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.logging.v2.LogMetric() - ); - client.innerApiCalls.updateLogMetric = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateLogMetric( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogMetric|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLogMetric with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateLogMetric = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateLogMetric(request), expectedError); - const actualRequest = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLogMetric with closed client', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.UpdateLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.UpdateLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateLogMetric(request), expectedError); - }); - }); - - describe('deleteLogMetric', () => { - it('invokes deleteLogMetric without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteLogMetric = stubSimpleCall(expectedResponse); - const [response] = await client.deleteLogMetric(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLogMetric without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteLogMetric = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteLogMetric( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLogMetric with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedHeaderRequestParams = `metric_name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteLogMetric = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteLogMetric(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteLogMetric as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteLogMetric with closed client', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.DeleteLogMetricRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.DeleteLogMetricRequest', ['metricName']); - request.metricName = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteLogMetric(request), expectedError); - }); - }); - - describe('listLogMetrics', () => { - it('invokes listLogMetrics without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - ]; - client.innerApiCalls.listLogMetrics = stubSimpleCall(expectedResponse); - const [response] = await client.listLogMetrics(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogMetrics without error using callback', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - ]; - client.innerApiCalls.listLogMetrics = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listLogMetrics( - request, - (err?: Error|null, result?: protos.google.logging.v2.ILogMetric[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogMetrics with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listLogMetrics = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listLogMetrics(request), expectedError); - const actualRequest = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listLogMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listLogMetricsStream without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - ]; - client.descriptors.page.listLogMetrics.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listLogMetricsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogMetric[] = []; - stream.on('data', (response: protos.google.logging.v2.LogMetric) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listLogMetrics.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogMetrics, request)); - assert( - (client.descriptors.page.listLogMetrics.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listLogMetricsStream with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listLogMetrics.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listLogMetricsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.logging.v2.LogMetric[] = []; - stream.on('data', (response: protos.google.logging.v2.LogMetric) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listLogMetrics.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listLogMetrics, request)); - assert( - (client.descriptors.page.listLogMetrics.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listLogMetrics without error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - generateSampleMessage(new protos.google.logging.v2.LogMetric()), - ]; - client.descriptors.page.listLogMetrics.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.logging.v2.ILogMetric[] = []; - const iterable = client.listLogMetricsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listLogMetrics.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listLogMetrics.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listLogMetrics with error', async () => { - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.logging.v2.ListLogMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.logging.v2.ListLogMetricsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listLogMetrics.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listLogMetricsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.logging.v2.ILogMetric[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listLogMetrics.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listLogMetrics.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('billingAccountCmekSettings', async () => { - const fakePath = "/rendered/path/billingAccountCmekSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountCmekSettingsPath', () => { - const result = client.billingAccountCmekSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountCmekSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountCmekSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountExclusion', async () => { - const fakePath = "/rendered/path/billingAccountExclusion"; - const expectedParameters = { - billing_account: "billingAccountValue", - exclusion: "exclusionValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountExclusionPath', () => { - const result = client.billingAccountExclusionPath("billingAccountValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountExclusionName', () => { - const result = client.matchBillingAccountFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromBillingAccountExclusionName', () => { - const result = client.matchExclusionFromBillingAccountExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.billingAccountExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucket', async () => { - const fakePath = "/rendered/path/billingAccountLocationBucket"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketPath', () => { - const result = client.billingAccountLocationBucketPath("billingAccountValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLocationBucketView', async () => { - const fakePath = "/rendered/path/billingAccountLocationBucketView"; - const expectedParameters = { - billing_account: "billingAccountValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLocationBucketViewPath', () => { - const result = client.billingAccountLocationBucketViewPath("billingAccountValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBillingAccountFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBillingAccountLocationBucketViewName', () => { - const result = client.matchLocationFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromBillingAccountLocationBucketViewName', () => { - const result = client.matchBucketFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromBillingAccountLocationBucketViewName', () => { - const result = client.matchViewFromBillingAccountLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.billingAccountLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountLog', async () => { - const fakePath = "/rendered/path/billingAccountLog"; - const expectedParameters = { - billing_account: "billingAccountValue", - log: "logValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountLogPath', () => { - const result = client.billingAccountLogPath("billingAccountValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountLogName', () => { - const result = client.matchBillingAccountFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromBillingAccountLogName', () => { - const result = client.matchLogFromBillingAccountLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.billingAccountLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSettings', async () => { - const fakePath = "/rendered/path/billingAccountSettings"; - const expectedParameters = { - billing_account: "billingAccountValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSettingsPath', () => { - const result = client.billingAccountSettingsPath("billingAccountValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSettingsName', () => { - const result = client.matchBillingAccountFromBillingAccountSettingsName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('billingAccountSink', async () => { - const fakePath = "/rendered/path/billingAccountSink"; - const expectedParameters = { - billing_account: "billingAccountValue", - sink: "sinkValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.billingAccountSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.billingAccountSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('billingAccountSinkPath', () => { - const result = client.billingAccountSinkPath("billingAccountValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.billingAccountSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchBillingAccountFromBillingAccountSinkName', () => { - const result = client.matchBillingAccountFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "billingAccountValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromBillingAccountSinkName', () => { - const result = client.matchSinkFromBillingAccountSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.billingAccountSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderCmekSettings', async () => { - const fakePath = "/rendered/path/folderCmekSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderCmekSettingsPath', () => { - const result = client.folderCmekSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderCmekSettingsName', () => { - const result = client.matchFolderFromFolderCmekSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderExclusion', async () => { - const fakePath = "/rendered/path/folderExclusion"; - const expectedParameters = { - folder: "folderValue", - exclusion: "exclusionValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderExclusionPath', () => { - const result = client.folderExclusionPath("folderValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderExclusionName', () => { - const result = client.matchFolderFromFolderExclusionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromFolderExclusionName', () => { - const result = client.matchExclusionFromFolderExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.folderExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucket', async () => { - const fakePath = "/rendered/path/folderLocationBucket"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketPath', () => { - const result = client.folderLocationBucketPath("folderValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketName', () => { - const result = client.matchFolderFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketName', () => { - const result = client.matchLocationFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketName', () => { - const result = client.matchBucketFromFolderLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLocationBucketView', async () => { - const fakePath = "/rendered/path/folderLocationBucketView"; - const expectedParameters = { - folder: "folderValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLocationBucketViewPath', () => { - const result = client.folderLocationBucketViewPath("folderValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLocationBucketViewName', () => { - const result = client.matchFolderFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromFolderLocationBucketViewName', () => { - const result = client.matchLocationFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromFolderLocationBucketViewName', () => { - const result = client.matchBucketFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromFolderLocationBucketViewName', () => { - const result = client.matchViewFromFolderLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.folderLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderLog', async () => { - const fakePath = "/rendered/path/folderLog"; - const expectedParameters = { - folder: "folderValue", - log: "logValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderLogPath', () => { - const result = client.folderLogPath("folderValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderLogName', () => { - const result = client.matchFolderFromFolderLogName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromFolderLogName', () => { - const result = client.matchLogFromFolderLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.folderLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSettings', async () => { - const fakePath = "/rendered/path/folderSettings"; - const expectedParameters = { - folder: "folderValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSettingsPath', () => { - const result = client.folderSettingsPath("folderValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSettingsName', () => { - const result = client.matchFolderFromFolderSettingsName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderSink', async () => { - const fakePath = "/rendered/path/folderSink"; - const expectedParameters = { - folder: "folderValue", - sink: "sinkValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderSinkPath', () => { - const result = client.folderSinkPath("folderValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderSinkName', () => { - const result = client.matchFolderFromFolderSinkName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromFolderSinkName', () => { - const result = client.matchSinkFromFolderSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.folderSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('logMetric', async () => { - const fakePath = "/rendered/path/logMetric"; - const expectedParameters = { - project: "projectValue", - metric: "metricValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.logMetricPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.logMetricPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('logMetricPath', () => { - const result = client.logMetricPath("projectValue", "metricValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.logMetricPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLogMetricName', () => { - const result = client.matchProjectFromLogMetricName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricFromLogMetricName', () => { - const result = client.matchMetricFromLogMetricName(fakePath); - assert.strictEqual(result, "metricValue"); - assert((client.pathTemplates.logMetricPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationCmekSettings', async () => { - const fakePath = "/rendered/path/organizationCmekSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationCmekSettingsPath', () => { - const result = client.organizationCmekSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationCmekSettingsName', () => { - const result = client.matchOrganizationFromOrganizationCmekSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationExclusion', async () => { - const fakePath = "/rendered/path/organizationExclusion"; - const expectedParameters = { - organization: "organizationValue", - exclusion: "exclusionValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationExclusionPath', () => { - const result = client.organizationExclusionPath("organizationValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationExclusionName', () => { - const result = client.matchOrganizationFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromOrganizationExclusionName', () => { - const result = client.matchExclusionFromOrganizationExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.organizationExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucket', async () => { - const fakePath = "/rendered/path/organizationLocationBucket"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketPath', () => { - const result = client.organizationLocationBucketPath("organizationValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketName', () => { - const result = client.matchLocationFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketName', () => { - const result = client.matchBucketFromOrganizationLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLocationBucketView', async () => { - const fakePath = "/rendered/path/organizationLocationBucketView"; - const expectedParameters = { - organization: "organizationValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLocationBucketViewPath', () => { - const result = client.organizationLocationBucketViewPath("organizationValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLocationBucketViewName', () => { - const result = client.matchOrganizationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromOrganizationLocationBucketViewName', () => { - const result = client.matchLocationFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromOrganizationLocationBucketViewName', () => { - const result = client.matchBucketFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromOrganizationLocationBucketViewName', () => { - const result = client.matchViewFromOrganizationLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.organizationLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationLog', async () => { - const fakePath = "/rendered/path/organizationLog"; - const expectedParameters = { - organization: "organizationValue", - log: "logValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationLogPath', () => { - const result = client.organizationLogPath("organizationValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationLogName', () => { - const result = client.matchOrganizationFromOrganizationLogName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromOrganizationLogName', () => { - const result = client.matchLogFromOrganizationLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.organizationLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSettings', async () => { - const fakePath = "/rendered/path/organizationSettings"; - const expectedParameters = { - organization: "organizationValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSettingsPath', () => { - const result = client.organizationSettingsPath("organizationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSettingsName', () => { - const result = client.matchOrganizationFromOrganizationSettingsName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationSink', async () => { - const fakePath = "/rendered/path/organizationSink"; - const expectedParameters = { - organization: "organizationValue", - sink: "sinkValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationSinkPath', () => { - const result = client.organizationSinkPath("organizationValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationSinkName', () => { - const result = client.matchOrganizationFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromOrganizationSinkName', () => { - const result = client.matchSinkFromOrganizationSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.organizationSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectCmekSettings', async () => { - const fakePath = "/rendered/path/projectCmekSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectCmekSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectCmekSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectCmekSettingsPath', () => { - const result = client.projectCmekSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectCmekSettingsName', () => { - const result = client.matchProjectFromProjectCmekSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectCmekSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectExclusion', async () => { - const fakePath = "/rendered/path/projectExclusion"; - const expectedParameters = { - project: "projectValue", - exclusion: "exclusionValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectExclusionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectExclusionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectExclusionPath', () => { - const result = client.projectExclusionPath("projectValue", "exclusionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectExclusionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectExclusionName', () => { - const result = client.matchProjectFromProjectExclusionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExclusionFromProjectExclusionName', () => { - const result = client.matchExclusionFromProjectExclusionName(fakePath); - assert.strictEqual(result, "exclusionValue"); - assert((client.pathTemplates.projectExclusionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucket', async () => { - const fakePath = "/rendered/path/projectLocationBucket"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLocationBucketPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketPath', () => { - const result = client.projectLocationBucketPath("projectValue", "locationValue", "bucketValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketName', () => { - const result = client.matchProjectFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketName', () => { - const result = client.matchLocationFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketName', () => { - const result = client.matchBucketFromProjectLocationBucketName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLocationBucketView', async () => { - const fakePath = "/rendered/path/projectLocationBucketView"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - bucket: "bucketValue", - view: "viewValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLocationBucketViewPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLocationBucketViewPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLocationBucketViewPath', () => { - const result = client.projectLocationBucketViewPath("projectValue", "locationValue", "bucketValue", "viewValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLocationBucketViewName', () => { - const result = client.matchProjectFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProjectLocationBucketViewName', () => { - const result = client.matchLocationFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBucketFromProjectLocationBucketViewName', () => { - const result = client.matchBucketFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "bucketValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchViewFromProjectLocationBucketViewName', () => { - const result = client.matchViewFromProjectLocationBucketViewName(fakePath); - assert.strictEqual(result, "viewValue"); - assert((client.pathTemplates.projectLocationBucketViewPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectLog', async () => { - const fakePath = "/rendered/path/projectLog"; - const expectedParameters = { - project: "projectValue", - log: "logValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectLogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectLogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectLogPath', () => { - const result = client.projectLogPath("projectValue", "logValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectLogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectLogName', () => { - const result = client.matchProjectFromProjectLogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLogFromProjectLogName', () => { - const result = client.matchLogFromProjectLogName(fakePath); - assert.strictEqual(result, "logValue"); - assert((client.pathTemplates.projectLogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSettings', async () => { - const fakePath = "/rendered/path/projectSettings"; - const expectedParameters = { - project: "projectValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectSettingsPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSettingsPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSettingsPath', () => { - const result = client.projectSettingsPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSettingsPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSettingsName', () => { - const result = client.matchProjectFromProjectSettingsName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSettingsPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectSink', async () => { - const fakePath = "/rendered/path/projectSink"; - const expectedParameters = { - project: "projectValue", - sink: "sinkValue", - }; - const client = new metricsservicev2Module.v2.MetricsServiceV2Client({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectSinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectSinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectSinkPath', () => { - const result = client.projectSinkPath("projectValue", "sinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectSinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectSinkName', () => { - const result = client.matchProjectFromProjectSinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchSinkFromProjectSinkName', () => { - const result = client.matchSinkFromProjectSinkName(fakePath); - assert.strictEqual(result, "sinkValue"); - assert((client.pathTemplates.projectSinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/logging/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/logging/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/logging/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/logging/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index cc002fa20ab1..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const monitoring = require('monitoring'); - -function main() { - const alertPolicyServiceClient = new monitoring.AlertPolicyServiceClient(); - const groupServiceClient = new monitoring.GroupServiceClient(); - const metricServiceClient = new monitoring.MetricServiceClient(); - const notificationChannelServiceClient = new monitoring.NotificationChannelServiceClient(); - const serviceMonitoringServiceClient = new monitoring.ServiceMonitoringServiceClient(); - const uptimeCheckServiceClient = new monitoring.UptimeCheckServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index bf1d810273f7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as monitoring from 'monitoring'; - -function main() { - const alertPolicyServiceClient = new monitoring.AlertPolicyServiceClient(); - const groupServiceClient = new monitoring.GroupServiceClient(); - const metricServiceClient = new monitoring.MetricServiceClient(); - const notificationChannelServiceClient = new monitoring.NotificationChannelServiceClient(); - const serviceMonitoringServiceClient = new monitoring.ServiceMonitoringServiceClient(); - const uptimeCheckServiceClient = new monitoring.UptimeCheckServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 826cea87912e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,63 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {AlertPolicyServiceClient, GroupServiceClient, MetricServiceClient, NotificationChannelServiceClient, ServiceMonitoringServiceClient, UptimeCheckServiceClient} from 'monitoring'; - -// check that the client class type name can be used -function doStuffWithAlertPolicyServiceClient(client: AlertPolicyServiceClient) { - client.close(); -} -function doStuffWithGroupServiceClient(client: GroupServiceClient) { - client.close(); -} -function doStuffWithMetricServiceClient(client: MetricServiceClient) { - client.close(); -} -function doStuffWithNotificationChannelServiceClient(client: NotificationChannelServiceClient) { - client.close(); -} -function doStuffWithServiceMonitoringServiceClient(client: ServiceMonitoringServiceClient) { - client.close(); -} -function doStuffWithUptimeCheckServiceClient(client: UptimeCheckServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const alertPolicyServiceClient = new AlertPolicyServiceClient(); - doStuffWithAlertPolicyServiceClient(alertPolicyServiceClient); - // check that the client instance can be created - const groupServiceClient = new GroupServiceClient(); - doStuffWithGroupServiceClient(groupServiceClient); - // check that the client instance can be created - const metricServiceClient = new MetricServiceClient(); - doStuffWithMetricServiceClient(metricServiceClient); - // check that the client instance can be created - const notificationChannelServiceClient = new NotificationChannelServiceClient(); - doStuffWithNotificationChannelServiceClient(notificationChannelServiceClient); - // check that the client instance can be created - const serviceMonitoringServiceClient = new ServiceMonitoringServiceClient(); - doStuffWithServiceMonitoringServiceClient(serviceMonitoringServiceClient); - // check that the client instance can be created - const uptimeCheckServiceClient = new UptimeCheckServiceClient(); - doStuffWithUptimeCheckServiceClient(uptimeCheckServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_alert_policy_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_alert_policy_service_v3.ts.baseline deleted file mode 100644 index 9e9365388883..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_alert_policy_service_v3.ts.baseline +++ /dev/null @@ -1,1914 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as alertpolicyserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.AlertPolicyServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = alertpolicyserviceModule.v3.AlertPolicyServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = alertpolicyserviceModule.v3.AlertPolicyServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new alertpolicyserviceModule.v3.AlertPolicyServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = alertpolicyserviceModule.v3.AlertPolicyServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.alertPolicyServiceStub, undefined); - await client.initialize(); - assert(client.alertPolicyServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.alertPolicyServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.alertPolicyServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - 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); - }); - }); - - describe('getAlertPolicy', () => { - it('invokes getAlertPolicy without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.getAlertPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.getAlertPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertPolicy without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.getAlertPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getAlertPolicy( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IAlertPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertPolicy with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getAlertPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getAlertPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertPolicy with closed client', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getAlertPolicy(request), expectedError); - }); - }); - - describe('createAlertPolicy', () => { - it('invokes createAlertPolicy without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.createAlertPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.createAlertPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createAlertPolicy without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.createAlertPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createAlertPolicy( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IAlertPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createAlertPolicy with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createAlertPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createAlertPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createAlertPolicy with closed client', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createAlertPolicy(request), expectedError); - }); - }); - - describe('deleteAlertPolicy', () => { - it('invokes deleteAlertPolicy without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteAlertPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.deleteAlertPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteAlertPolicy without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteAlertPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteAlertPolicy( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteAlertPolicy with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteAlertPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteAlertPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteAlertPolicy with closed client', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteAlertPolicy(request), expectedError); - }); - }); - - describe('updateAlertPolicy', () => { - it('invokes updateAlertPolicy without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateAlertPolicyRequest() - ); - request.alertPolicy ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateAlertPolicyRequest', ['alertPolicy', 'name']); - request.alertPolicy.name = defaultValue1; - const expectedHeaderRequestParams = `alert_policy.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.updateAlertPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.updateAlertPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertPolicy without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateAlertPolicyRequest() - ); - request.alertPolicy ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateAlertPolicyRequest', ['alertPolicy', 'name']); - request.alertPolicy.name = defaultValue1; - const expectedHeaderRequestParams = `alert_policy.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.updateAlertPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateAlertPolicy( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IAlertPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertPolicy with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateAlertPolicyRequest() - ); - request.alertPolicy ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateAlertPolicyRequest', ['alertPolicy', 'name']); - request.alertPolicy.name = defaultValue1; - const expectedHeaderRequestParams = `alert_policy.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateAlertPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateAlertPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertPolicy with closed client', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateAlertPolicyRequest() - ); - request.alertPolicy ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateAlertPolicyRequest', ['alertPolicy', 'name']); - request.alertPolicy.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateAlertPolicy(request), expectedError); - }); - }); - - describe('listAlertPolicies', () => { - it('invokes listAlertPolicies without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - ]; - client.innerApiCalls.listAlertPolicies = stubSimpleCall(expectedResponse); - const [response] = await client.listAlertPolicies(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listAlertPolicies without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - ]; - client.innerApiCalls.listAlertPolicies = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listAlertPolicies( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IAlertPolicy[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listAlertPolicies with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listAlertPolicies = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listAlertPolicies(request), expectedError); - const actualRequest = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listAlertPoliciesStream without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - ]; - client.descriptors.page.listAlertPolicies.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listAlertPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.AlertPolicy[] = []; - stream.on('data', (response: protos.google.monitoring.v3.AlertPolicy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listAlertPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listAlertPolicies, request)); - assert( - (client.descriptors.page.listAlertPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listAlertPoliciesStream with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listAlertPolicies.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listAlertPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.AlertPolicy[] = []; - stream.on('data', (response: protos.google.monitoring.v3.AlertPolicy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listAlertPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listAlertPolicies, request)); - assert( - (client.descriptors.page.listAlertPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listAlertPolicies without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - ]; - client.descriptors.page.listAlertPolicies.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IAlertPolicy[] = []; - const iterable = client.listAlertPoliciesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listAlertPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listAlertPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listAlertPolicies with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listAlertPolicies.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listAlertPoliciesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IAlertPolicy[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listAlertPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listAlertPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_group_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_group_service_v3.ts.baseline deleted file mode 100644 index 16ae9b02f3ab..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_group_service_v3.ts.baseline +++ /dev/null @@ -1,2159 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as groupserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.GroupServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new groupserviceModule.v3.GroupServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new groupserviceModule.v3.GroupServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = groupserviceModule.v3.GroupServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = groupserviceModule.v3.GroupServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new groupserviceModule.v3.GroupServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new groupserviceModule.v3.GroupServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new groupserviceModule.v3.GroupServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new groupserviceModule.v3.GroupServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new groupserviceModule.v3.GroupServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = groupserviceModule.v3.GroupServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new groupserviceModule.v3.GroupServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.groupServiceStub, undefined); - await client.initialize(); - assert(client.groupServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.groupServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.groupServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new groupserviceModule.v3.GroupServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new groupserviceModule.v3.GroupServiceClient({ - 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); - }); - }); - - describe('getGroup', () => { - it('invokes getGroup without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.getGroup = stubSimpleCall(expectedResponse); - const [response] = await client.getGroup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGroup without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.getGroup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getGroup( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGroup|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGroup with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getGroup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getGroup(request), expectedError); - const actualRequest = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGroup with closed client', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetGroupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getGroup(request), expectedError); - }); - }); - - describe('createGroup', () => { - it('invokes createGroup without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.createGroup = stubSimpleCall(expectedResponse); - const [response] = await client.createGroup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGroup without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.createGroup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createGroup( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGroup|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGroup with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createGroup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createGroup(request), expectedError); - const actualRequest = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGroup with closed client', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateGroupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createGroup(request), expectedError); - }); - }); - - describe('updateGroup', () => { - it('invokes updateGroup without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateGroupRequest() - ); - request.group ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateGroupRequest', ['group', 'name']); - request.group.name = defaultValue1; - const expectedHeaderRequestParams = `group.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.updateGroup = stubSimpleCall(expectedResponse); - const [response] = await client.updateGroup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGroup without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateGroupRequest() - ); - request.group ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateGroupRequest', ['group', 'name']); - request.group.name = defaultValue1; - const expectedHeaderRequestParams = `group.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.updateGroup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateGroup( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGroup|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGroup with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateGroupRequest() - ); - request.group ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateGroupRequest', ['group', 'name']); - request.group.name = defaultValue1; - const expectedHeaderRequestParams = `group.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateGroup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateGroup(request), expectedError); - const actualRequest = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGroup with closed client', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateGroupRequest() - ); - request.group ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateGroupRequest', ['group', 'name']); - request.group.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateGroup(request), expectedError); - }); - }); - - describe('deleteGroup', () => { - it('invokes deleteGroup without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteGroup = stubSimpleCall(expectedResponse); - const [response] = await client.deleteGroup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGroup without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteGroup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteGroup( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGroup with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteGroup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteGroup(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGroup with closed client', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteGroupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteGroup(request), expectedError); - }); - }); - - describe('listGroups', () => { - it('invokes listGroups without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - ]; - client.innerApiCalls.listGroups = stubSimpleCall(expectedResponse); - const [response] = await client.listGroups(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroups without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - ]; - client.innerApiCalls.listGroups = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listGroups( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGroup[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroups with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listGroups = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listGroups(request), expectedError); - const actualRequest = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroupsStream without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - ]; - client.descriptors.page.listGroups.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listGroupsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.Group[] = []; - stream.on('data', (response: protos.google.monitoring.v3.Group) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listGroups.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGroups, request)); - assert( - (client.descriptors.page.listGroups.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listGroupsStream with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGroups.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listGroupsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.Group[] = []; - stream.on('data', (response: protos.google.monitoring.v3.Group) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listGroups.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGroups, request)); - assert( - (client.descriptors.page.listGroups.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGroups without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - ]; - client.descriptors.page.listGroups.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IGroup[] = []; - const iterable = client.listGroupsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listGroups.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGroups.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGroups with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGroups.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listGroupsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IGroup[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listGroups.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGroups.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listGroupMembers', () => { - it('invokes listGroupMembers without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - ]; - client.innerApiCalls.listGroupMembers = stubSimpleCall(expectedResponse); - const [response] = await client.listGroupMembers(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroupMembers without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - ]; - client.innerApiCalls.listGroupMembers = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listGroupMembers( - request, - (err?: Error|null, result?: protos.google.api.IMonitoredResource[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroupMembers with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listGroupMembers = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listGroupMembers(request), expectedError); - const actualRequest = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroupMembersStream without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - ]; - client.descriptors.page.listGroupMembers.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listGroupMembersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResource[] = []; - stream.on('data', (response: protos.google.api.MonitoredResource) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listGroupMembers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGroupMembers, request)); - assert( - (client.descriptors.page.listGroupMembers.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listGroupMembersStream with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGroupMembers.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listGroupMembersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResource[] = []; - stream.on('data', (response: protos.google.api.MonitoredResource) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listGroupMembers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGroupMembers, request)); - assert( - (client.descriptors.page.listGroupMembers.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGroupMembers without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - ]; - client.descriptors.page.listGroupMembers.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.api.IMonitoredResource[] = []; - const iterable = client.listGroupMembersAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listGroupMembers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGroupMembers.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGroupMembers with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGroupMembers.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listGroupMembersAsync(request); - await assert.rejects(async () => { - const responses: protos.google.api.IMonitoredResource[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listGroupMembers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGroupMembers.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_metric_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_metric_service_v3.ts.baseline deleted file mode 100644 index d837dd6e58c0..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_metric_service_v3.ts.baseline +++ /dev/null @@ -1,2736 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as metricserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.MetricServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new metricserviceModule.v3.MetricServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new metricserviceModule.v3.MetricServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = metricserviceModule.v3.MetricServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = metricserviceModule.v3.MetricServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new metricserviceModule.v3.MetricServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new metricserviceModule.v3.MetricServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new metricserviceModule.v3.MetricServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new metricserviceModule.v3.MetricServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new metricserviceModule.v3.MetricServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = metricserviceModule.v3.MetricServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new metricserviceModule.v3.MetricServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.metricServiceStub, undefined); - await client.initialize(); - assert(client.metricServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.metricServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.metricServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new metricserviceModule.v3.MetricServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new metricserviceModule.v3.MetricServiceClient({ - 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); - }); - }); - - describe('getMonitoredResourceDescriptor', () => { - it('invokes getMonitoredResourceDescriptor without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMonitoredResourceDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMonitoredResourceDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MonitoredResourceDescriptor() - ); - client.innerApiCalls.getMonitoredResourceDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.getMonitoredResourceDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMonitoredResourceDescriptor without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMonitoredResourceDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMonitoredResourceDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MonitoredResourceDescriptor() - ); - client.innerApiCalls.getMonitoredResourceDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getMonitoredResourceDescriptor( - request, - (err?: Error|null, result?: protos.google.api.IMonitoredResourceDescriptor|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMonitoredResourceDescriptor with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMonitoredResourceDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMonitoredResourceDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getMonitoredResourceDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getMonitoredResourceDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMonitoredResourceDescriptor with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMonitoredResourceDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMonitoredResourceDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getMonitoredResourceDescriptor(request), expectedError); - }); - }); - - describe('getMetricDescriptor', () => { - it('invokes getMetricDescriptor without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MetricDescriptor() - ); - client.innerApiCalls.getMetricDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.getMetricDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMetricDescriptor without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MetricDescriptor() - ); - client.innerApiCalls.getMetricDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getMetricDescriptor( - request, - (err?: Error|null, result?: protos.google.api.IMetricDescriptor|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMetricDescriptor with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getMetricDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getMetricDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMetricDescriptor with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getMetricDescriptor(request), expectedError); - }); - }); - - describe('createMetricDescriptor', () => { - it('invokes createMetricDescriptor without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MetricDescriptor() - ); - client.innerApiCalls.createMetricDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.createMetricDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMetricDescriptor without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MetricDescriptor() - ); - client.innerApiCalls.createMetricDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createMetricDescriptor( - request, - (err?: Error|null, result?: protos.google.api.IMetricDescriptor|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMetricDescriptor with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createMetricDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createMetricDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMetricDescriptor with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createMetricDescriptor(request), expectedError); - }); - }); - - describe('deleteMetricDescriptor', () => { - it('invokes deleteMetricDescriptor without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteMetricDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.deleteMetricDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMetricDescriptor without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteMetricDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteMetricDescriptor( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMetricDescriptor with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteMetricDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteMetricDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMetricDescriptor with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteMetricDescriptor(request), expectedError); - }); - }); - - describe('createTimeSeries', () => { - it('invokes createTimeSeries without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.createTimeSeries = stubSimpleCall(expectedResponse); - const [response] = await client.createTimeSeries(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTimeSeries without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.createTimeSeries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createTimeSeries( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTimeSeries with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createTimeSeries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createTimeSeries(request), expectedError); - const actualRequest = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTimeSeries with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createTimeSeries(request), expectedError); - }); - }); - - describe('listMonitoredResourceDescriptors', () => { - it('invokes listMonitoredResourceDescriptors without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCall(expectedResponse); - const [response] = await client.listMonitoredResourceDescriptors(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMonitoredResourceDescriptors without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listMonitoredResourceDescriptors( - request, - (err?: Error|null, result?: protos.google.api.IMonitoredResourceDescriptor[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMonitoredResourceDescriptors with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listMonitoredResourceDescriptors(request), expectedError); - const actualRequest = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMonitoredResourceDescriptorsStream without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.descriptors.page.listMonitoredResourceDescriptors.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listMonitoredResourceDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResourceDescriptor[] = []; - stream.on('data', (response: protos.google.api.MonitoredResourceDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMonitoredResourceDescriptors, request)); - assert( - (client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listMonitoredResourceDescriptorsStream with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listMonitoredResourceDescriptors.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listMonitoredResourceDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResourceDescriptor[] = []; - stream.on('data', (response: protos.google.api.MonitoredResourceDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMonitoredResourceDescriptors, request)); - assert( - (client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listMonitoredResourceDescriptors without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.api.IMonitoredResourceDescriptor[] = []; - const iterable = client.listMonitoredResourceDescriptorsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listMonitoredResourceDescriptors with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listMonitoredResourceDescriptorsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.api.IMonitoredResourceDescriptor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listMetricDescriptors', () => { - it('invokes listMetricDescriptors without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - ]; - client.innerApiCalls.listMetricDescriptors = stubSimpleCall(expectedResponse); - const [response] = await client.listMetricDescriptors(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMetricDescriptors without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - ]; - client.innerApiCalls.listMetricDescriptors = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listMetricDescriptors( - request, - (err?: Error|null, result?: protos.google.api.IMetricDescriptor[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMetricDescriptors with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listMetricDescriptors = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listMetricDescriptors(request), expectedError); - const actualRequest = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMetricDescriptorsStream without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - ]; - client.descriptors.page.listMetricDescriptors.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listMetricDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MetricDescriptor[] = []; - stream.on('data', (response: protos.google.api.MetricDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listMetricDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMetricDescriptors, request)); - assert( - (client.descriptors.page.listMetricDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listMetricDescriptorsStream with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listMetricDescriptors.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listMetricDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MetricDescriptor[] = []; - stream.on('data', (response: protos.google.api.MetricDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listMetricDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMetricDescriptors, request)); - assert( - (client.descriptors.page.listMetricDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listMetricDescriptors without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - ]; - client.descriptors.page.listMetricDescriptors.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.api.IMetricDescriptor[] = []; - const iterable = client.listMetricDescriptorsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listMetricDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listMetricDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listMetricDescriptors with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listMetricDescriptors.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listMetricDescriptorsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.api.IMetricDescriptor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listMetricDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listMetricDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listTimeSeries', () => { - it('invokes listTimeSeries without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - ]; - client.innerApiCalls.listTimeSeries = stubSimpleCall(expectedResponse); - const [response] = await client.listTimeSeries(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTimeSeries without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - ]; - client.innerApiCalls.listTimeSeries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTimeSeries( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.ITimeSeries[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTimeSeries with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTimeSeries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTimeSeries(request), expectedError); - const actualRequest = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTimeSeriesStream without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - ]; - client.descriptors.page.listTimeSeries.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTimeSeriesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.TimeSeries[] = []; - stream.on('data', (response: protos.google.monitoring.v3.TimeSeries) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTimeSeries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTimeSeries, request)); - assert( - (client.descriptors.page.listTimeSeries.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTimeSeriesStream with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTimeSeries.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTimeSeriesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.TimeSeries[] = []; - stream.on('data', (response: protos.google.monitoring.v3.TimeSeries) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTimeSeries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTimeSeries, request)); - assert( - (client.descriptors.page.listTimeSeries.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTimeSeries without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - ]; - client.descriptors.page.listTimeSeries.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.ITimeSeries[] = []; - const iterable = client.listTimeSeriesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTimeSeries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTimeSeries.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTimeSeries with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTimeSeries.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTimeSeriesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.ITimeSeries[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTimeSeries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTimeSeries.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderMetricDescriptor', () => { - const fakePath = "/rendered/path/folderMetricDescriptor"; - const expectedParameters = { - folder: "folderValue", - metric_descriptor: "metricDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderMetricDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderMetricDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderMetricDescriptorPath', () => { - const result = client.folderMetricDescriptorPath("folderValue", "metricDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderMetricDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderMetricDescriptorName', () => { - const result = client.matchFolderFromFolderMetricDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricDescriptorFromFolderMetricDescriptorName', () => { - const result = client.matchMetricDescriptorFromFolderMetricDescriptorName(fakePath); - assert.strictEqual(result, "metricDescriptorValue"); - assert((client.pathTemplates.folderMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderMonitoredResourceDescriptor', () => { - const fakePath = "/rendered/path/folderMonitoredResourceDescriptor"; - const expectedParameters = { - folder: "folderValue", - monitored_resource_descriptor: "monitoredResourceDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderMonitoredResourceDescriptorPath', () => { - const result = client.folderMonitoredResourceDescriptorPath("folderValue", "monitoredResourceDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderMonitoredResourceDescriptorName', () => { - const result = client.matchFolderFromFolderMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMonitoredResourceDescriptorFromFolderMonitoredResourceDescriptorName', () => { - const result = client.matchMonitoredResourceDescriptorFromFolderMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "monitoredResourceDescriptorValue"); - assert((client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationMetricDescriptor', () => { - const fakePath = "/rendered/path/organizationMetricDescriptor"; - const expectedParameters = { - organization: "organizationValue", - metric_descriptor: "metricDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationMetricDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationMetricDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationMetricDescriptorPath', () => { - const result = client.organizationMetricDescriptorPath("organizationValue", "metricDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationMetricDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationMetricDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationMetricDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricDescriptorFromOrganizationMetricDescriptorName', () => { - const result = client.matchMetricDescriptorFromOrganizationMetricDescriptorName(fakePath); - assert.strictEqual(result, "metricDescriptorValue"); - assert((client.pathTemplates.organizationMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationMonitoredResourceDescriptor', () => { - const fakePath = "/rendered/path/organizationMonitoredResourceDescriptor"; - const expectedParameters = { - organization: "organizationValue", - monitored_resource_descriptor: "monitoredResourceDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationMonitoredResourceDescriptorPath', () => { - const result = client.organizationMonitoredResourceDescriptorPath("organizationValue", "monitoredResourceDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationMonitoredResourceDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMonitoredResourceDescriptorFromOrganizationMonitoredResourceDescriptorName', () => { - const result = client.matchMonitoredResourceDescriptorFromOrganizationMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "monitoredResourceDescriptorValue"); - assert((client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectMetricDescriptor', () => { - const fakePath = "/rendered/path/projectMetricDescriptor"; - const expectedParameters = { - project: "projectValue", - metric_descriptor: "metricDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectMetricDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectMetricDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectMetricDescriptorPath', () => { - const result = client.projectMetricDescriptorPath("projectValue", "metricDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectMetricDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectMetricDescriptorName', () => { - const result = client.matchProjectFromProjectMetricDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricDescriptorFromProjectMetricDescriptorName', () => { - const result = client.matchMetricDescriptorFromProjectMetricDescriptorName(fakePath); - assert.strictEqual(result, "metricDescriptorValue"); - assert((client.pathTemplates.projectMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectMonitoredResourceDescriptor', () => { - const fakePath = "/rendered/path/projectMonitoredResourceDescriptor"; - const expectedParameters = { - project: "projectValue", - monitored_resource_descriptor: "monitoredResourceDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectMonitoredResourceDescriptorPath', () => { - const result = client.projectMonitoredResourceDescriptorPath("projectValue", "monitoredResourceDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectMonitoredResourceDescriptorName', () => { - const result = client.matchProjectFromProjectMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMonitoredResourceDescriptorFromProjectMonitoredResourceDescriptorName', () => { - const result = client.matchMonitoredResourceDescriptorFromProjectMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "monitoredResourceDescriptorValue"); - assert((client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_notification_channel_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_notification_channel_service_v3.ts.baseline deleted file mode 100644 index b8f5cbb4948e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_notification_channel_service_v3.ts.baseline +++ /dev/null @@ -1,2591 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as notificationchannelserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.NotificationChannelServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = notificationchannelserviceModule.v3.NotificationChannelServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = notificationchannelserviceModule.v3.NotificationChannelServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new notificationchannelserviceModule.v3.NotificationChannelServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = notificationchannelserviceModule.v3.NotificationChannelServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.notificationChannelServiceStub, undefined); - await client.initialize(); - assert(client.notificationChannelServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.notificationChannelServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.notificationChannelServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - 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); - }); - }); - - describe('getNotificationChannelDescriptor', () => { - it('invokes getNotificationChannelDescriptor without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannelDescriptor() - ); - client.innerApiCalls.getNotificationChannelDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.getNotificationChannelDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelDescriptor without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannelDescriptor() - ); - client.innerApiCalls.getNotificationChannelDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getNotificationChannelDescriptor( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannelDescriptor|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelDescriptor with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getNotificationChannelDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getNotificationChannelDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelDescriptor with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getNotificationChannelDescriptor(request), expectedError); - }); - }); - - describe('getNotificationChannel', () => { - it('invokes getNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.getNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.getNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.getNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getNotificationChannel( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getNotificationChannel(request), expectedError); - }); - }); - - describe('createNotificationChannel', () => { - it('invokes createNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.createNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.createNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.createNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createNotificationChannel( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createNotificationChannel(request), expectedError); - }); - }); - - describe('updateNotificationChannel', () => { - it('invokes updateNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateNotificationChannelRequest() - ); - request.notificationChannel ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateNotificationChannelRequest', ['notificationChannel', 'name']); - request.notificationChannel.name = defaultValue1; - const expectedHeaderRequestParams = `notification_channel.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.updateNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.updateNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateNotificationChannelRequest() - ); - request.notificationChannel ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateNotificationChannelRequest', ['notificationChannel', 'name']); - request.notificationChannel.name = defaultValue1; - const expectedHeaderRequestParams = `notification_channel.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.updateNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateNotificationChannel( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateNotificationChannelRequest() - ); - request.notificationChannel ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateNotificationChannelRequest', ['notificationChannel', 'name']); - request.notificationChannel.name = defaultValue1; - const expectedHeaderRequestParams = `notification_channel.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateNotificationChannelRequest() - ); - request.notificationChannel ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateNotificationChannelRequest', ['notificationChannel', 'name']); - request.notificationChannel.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateNotificationChannel(request), expectedError); - }); - }); - - describe('deleteNotificationChannel', () => { - it('invokes deleteNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.deleteNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteNotificationChannel( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteNotificationChannel(request), expectedError); - }); - }); - - describe('sendNotificationChannelVerificationCode', () => { - it('invokes sendNotificationChannelVerificationCode without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.sendNotificationChannelVerificationCode = stubSimpleCall(expectedResponse); - const [response] = await client.sendNotificationChannelVerificationCode(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes sendNotificationChannelVerificationCode without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.sendNotificationChannelVerificationCode = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.sendNotificationChannelVerificationCode( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes sendNotificationChannelVerificationCode with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.sendNotificationChannelVerificationCode = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.sendNotificationChannelVerificationCode(request), expectedError); - const actualRequest = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes sendNotificationChannelVerificationCode with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.sendNotificationChannelVerificationCode(request), expectedError); - }); - }); - - describe('getNotificationChannelVerificationCode', () => { - it('invokes getNotificationChannelVerificationCode without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeResponse() - ); - client.innerApiCalls.getNotificationChannelVerificationCode = stubSimpleCall(expectedResponse); - const [response] = await client.getNotificationChannelVerificationCode(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelVerificationCode without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeResponse() - ); - client.innerApiCalls.getNotificationChannelVerificationCode = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getNotificationChannelVerificationCode( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGetNotificationChannelVerificationCodeResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelVerificationCode with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getNotificationChannelVerificationCode = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getNotificationChannelVerificationCode(request), expectedError); - const actualRequest = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelVerificationCode with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getNotificationChannelVerificationCode(request), expectedError); - }); - }); - - describe('verifyNotificationChannel', () => { - it('invokes verifyNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.VerifyNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.VerifyNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.verifyNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.verifyNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.VerifyNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.VerifyNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.verifyNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyNotificationChannel( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.VerifyNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.VerifyNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.verifyNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.VerifyNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.VerifyNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyNotificationChannel(request), expectedError); - }); - }); - - describe('listNotificationChannelDescriptors', () => { - it('invokes listNotificationChannelDescriptors without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - ]; - client.innerApiCalls.listNotificationChannelDescriptors = stubSimpleCall(expectedResponse); - const [response] = await client.listNotificationChannelDescriptors(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannelDescriptors without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - ]; - client.innerApiCalls.listNotificationChannelDescriptors = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listNotificationChannelDescriptors( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannelDescriptor[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannelDescriptors with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listNotificationChannelDescriptors = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listNotificationChannelDescriptors(request), expectedError); - const actualRequest = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannelDescriptorsStream without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - ]; - client.descriptors.page.listNotificationChannelDescriptors.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listNotificationChannelDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.NotificationChannelDescriptor[] = []; - stream.on('data', (response: protos.google.monitoring.v3.NotificationChannelDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listNotificationChannelDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listNotificationChannelDescriptors, request)); - assert( - (client.descriptors.page.listNotificationChannelDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listNotificationChannelDescriptorsStream with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listNotificationChannelDescriptors.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listNotificationChannelDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.NotificationChannelDescriptor[] = []; - stream.on('data', (response: protos.google.monitoring.v3.NotificationChannelDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listNotificationChannelDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listNotificationChannelDescriptors, request)); - assert( - (client.descriptors.page.listNotificationChannelDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listNotificationChannelDescriptors without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - ]; - client.descriptors.page.listNotificationChannelDescriptors.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.INotificationChannelDescriptor[] = []; - const iterable = client.listNotificationChannelDescriptorsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listNotificationChannelDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listNotificationChannelDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listNotificationChannelDescriptors with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listNotificationChannelDescriptors.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listNotificationChannelDescriptorsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.INotificationChannelDescriptor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listNotificationChannelDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listNotificationChannelDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listNotificationChannels', () => { - it('invokes listNotificationChannels without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - ]; - client.innerApiCalls.listNotificationChannels = stubSimpleCall(expectedResponse); - const [response] = await client.listNotificationChannels(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannels without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - ]; - client.innerApiCalls.listNotificationChannels = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listNotificationChannels( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannels with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listNotificationChannels = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listNotificationChannels(request), expectedError); - const actualRequest = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannelsStream without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - ]; - client.descriptors.page.listNotificationChannels.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listNotificationChannelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.NotificationChannel[] = []; - stream.on('data', (response: protos.google.monitoring.v3.NotificationChannel) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listNotificationChannels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listNotificationChannels, request)); - assert( - (client.descriptors.page.listNotificationChannels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listNotificationChannelsStream with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listNotificationChannels.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listNotificationChannelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.NotificationChannel[] = []; - stream.on('data', (response: protos.google.monitoring.v3.NotificationChannel) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listNotificationChannels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listNotificationChannels, request)); - assert( - (client.descriptors.page.listNotificationChannels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listNotificationChannels without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - ]; - client.descriptors.page.listNotificationChannels.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.INotificationChannel[] = []; - const iterable = client.listNotificationChannelsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listNotificationChannels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listNotificationChannels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listNotificationChannels with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listNotificationChannels.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listNotificationChannelsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.INotificationChannel[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listNotificationChannels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listNotificationChannels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_service_monitoring_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_service_monitoring_service_v3.ts.baseline deleted file mode 100644 index eaa15a638191..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_service_monitoring_service_v3.ts.baseline +++ /dev/null @@ -1,2595 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as servicemonitoringserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.ServiceMonitoringServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.serviceMonitoringServiceStub, undefined); - await client.initialize(); - assert(client.serviceMonitoringServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.serviceMonitoringServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.serviceMonitoringServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - 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); - }); - }); - - describe('createService', () => { - it('invokes createService without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.createService = stubSimpleCall(expectedResponse); - const [response] = await client.createService(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createService without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.createService = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createService( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IService|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createService with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createService = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createService(request), expectedError); - const actualRequest = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createService with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createService(request), expectedError); - }); - }); - - describe('getService', () => { - it('invokes getService without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.getService = stubSimpleCall(expectedResponse); - const [response] = await client.getService(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getService without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.getService = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getService( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IService|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getService with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getService = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getService(request), expectedError); - const actualRequest = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getService with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getService(request), expectedError); - }); - }); - - describe('updateService', () => { - it('invokes updateService without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceRequest() - ); - request.service ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceRequest', ['service', 'name']); - request.service.name = defaultValue1; - const expectedHeaderRequestParams = `service.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.updateService = stubSimpleCall(expectedResponse); - const [response] = await client.updateService(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateService without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceRequest() - ); - request.service ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceRequest', ['service', 'name']); - request.service.name = defaultValue1; - const expectedHeaderRequestParams = `service.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.updateService = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateService( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IService|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateService with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceRequest() - ); - request.service ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceRequest', ['service', 'name']); - request.service.name = defaultValue1; - const expectedHeaderRequestParams = `service.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateService = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateService(request), expectedError); - const actualRequest = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateService with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceRequest() - ); - request.service ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceRequest', ['service', 'name']); - request.service.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateService(request), expectedError); - }); - }); - - describe('deleteService', () => { - it('invokes deleteService without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteService = stubSimpleCall(expectedResponse); - const [response] = await client.deleteService(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteService without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteService = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteService( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteService with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteService = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteService(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteService with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteService(request), expectedError); - }); - }); - - describe('createServiceLevelObjective', () => { - it('invokes createServiceLevelObjective without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceLevelObjectiveRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.createServiceLevelObjective = stubSimpleCall(expectedResponse); - const [response] = await client.createServiceLevelObjective(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServiceLevelObjective without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceLevelObjectiveRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.createServiceLevelObjective = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createServiceLevelObjective( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IServiceLevelObjective|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServiceLevelObjective with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceLevelObjectiveRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createServiceLevelObjective = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createServiceLevelObjective(request), expectedError); - const actualRequest = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServiceLevelObjective with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceLevelObjectiveRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createServiceLevelObjective(request), expectedError); - }); - }); - - describe('getServiceLevelObjective', () => { - it('invokes getServiceLevelObjective without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.getServiceLevelObjective = stubSimpleCall(expectedResponse); - const [response] = await client.getServiceLevelObjective(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceLevelObjective without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.getServiceLevelObjective = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getServiceLevelObjective( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IServiceLevelObjective|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceLevelObjective with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getServiceLevelObjective = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getServiceLevelObjective(request), expectedError); - const actualRequest = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceLevelObjective with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getServiceLevelObjective(request), expectedError); - }); - }); - - describe('updateServiceLevelObjective', () => { - it('invokes updateServiceLevelObjective without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceLevelObjectiveRequest() - ); - request.serviceLevelObjective ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceLevelObjectiveRequest', ['serviceLevelObjective', 'name']); - request.serviceLevelObjective.name = defaultValue1; - const expectedHeaderRequestParams = `service_level_objective.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.updateServiceLevelObjective = stubSimpleCall(expectedResponse); - const [response] = await client.updateServiceLevelObjective(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServiceLevelObjective without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceLevelObjectiveRequest() - ); - request.serviceLevelObjective ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceLevelObjectiveRequest', ['serviceLevelObjective', 'name']); - request.serviceLevelObjective.name = defaultValue1; - const expectedHeaderRequestParams = `service_level_objective.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.updateServiceLevelObjective = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateServiceLevelObjective( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IServiceLevelObjective|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServiceLevelObjective with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceLevelObjectiveRequest() - ); - request.serviceLevelObjective ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceLevelObjectiveRequest', ['serviceLevelObjective', 'name']); - request.serviceLevelObjective.name = defaultValue1; - const expectedHeaderRequestParams = `service_level_objective.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateServiceLevelObjective = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateServiceLevelObjective(request), expectedError); - const actualRequest = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServiceLevelObjective with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceLevelObjectiveRequest() - ); - request.serviceLevelObjective ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceLevelObjectiveRequest', ['serviceLevelObjective', 'name']); - request.serviceLevelObjective.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateServiceLevelObjective(request), expectedError); - }); - }); - - describe('deleteServiceLevelObjective', () => { - it('invokes deleteServiceLevelObjective without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteServiceLevelObjective = stubSimpleCall(expectedResponse); - const [response] = await client.deleteServiceLevelObjective(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServiceLevelObjective without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteServiceLevelObjective = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteServiceLevelObjective( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServiceLevelObjective with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteServiceLevelObjective = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteServiceLevelObjective(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServiceLevelObjective with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteServiceLevelObjective(request), expectedError); - }); - }); - - describe('listServices', () => { - it('invokes listServices without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - ]; - client.innerApiCalls.listServices = stubSimpleCall(expectedResponse); - const [response] = await client.listServices(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServices without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - ]; - client.innerApiCalls.listServices = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServices( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IService[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServices with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServices = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServices(request), expectedError); - const actualRequest = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServicesStream without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - ]; - client.descriptors.page.listServices.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listServicesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.Service[] = []; - stream.on('data', (response: protos.google.monitoring.v3.Service) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServices, request)); - assert( - (client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listServicesStream with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServices.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listServicesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.Service[] = []; - stream.on('data', (response: protos.google.monitoring.v3.Service) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServices, request)); - assert( - (client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServices without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - ]; - client.descriptors.page.listServices.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IService[] = []; - const iterable = client.listServicesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listServices.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServices.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServices with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServices.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listServicesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IService[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listServices.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServices.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listServiceLevelObjectives', () => { - it('invokes listServiceLevelObjectives without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - ]; - client.innerApiCalls.listServiceLevelObjectives = stubSimpleCall(expectedResponse); - const [response] = await client.listServiceLevelObjectives(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServiceLevelObjectives without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - ]; - client.innerApiCalls.listServiceLevelObjectives = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServiceLevelObjectives( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IServiceLevelObjective[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServiceLevelObjectives with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServiceLevelObjectives = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServiceLevelObjectives(request), expectedError); - const actualRequest = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServiceLevelObjectivesStream without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - ]; - client.descriptors.page.listServiceLevelObjectives.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listServiceLevelObjectivesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.ServiceLevelObjective[] = []; - stream.on('data', (response: protos.google.monitoring.v3.ServiceLevelObjective) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listServiceLevelObjectives.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServiceLevelObjectives, request)); - assert( - (client.descriptors.page.listServiceLevelObjectives.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listServiceLevelObjectivesStream with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServiceLevelObjectives.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listServiceLevelObjectivesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.ServiceLevelObjective[] = []; - stream.on('data', (response: protos.google.monitoring.v3.ServiceLevelObjective) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listServiceLevelObjectives.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServiceLevelObjectives, request)); - assert( - (client.descriptors.page.listServiceLevelObjectives.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServiceLevelObjectives without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - ]; - client.descriptors.page.listServiceLevelObjectives.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IServiceLevelObjective[] = []; - const iterable = client.listServiceLevelObjectivesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listServiceLevelObjectives.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServiceLevelObjectives.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServiceLevelObjectives with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServiceLevelObjectives.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listServiceLevelObjectivesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IServiceLevelObjective[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listServiceLevelObjectives.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServiceLevelObjectives.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_uptime_check_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_uptime_check_service_v3.ts.baseline deleted file mode 100644 index 8c656b1300af..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/esm/test/gapic_uptime_check_service_v3.ts.baseline +++ /dev/null @@ -1,2089 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as uptimecheckserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.UptimeCheckServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = uptimecheckserviceModule.v3.UptimeCheckServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = uptimecheckserviceModule.v3.UptimeCheckServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new uptimecheckserviceModule.v3.UptimeCheckServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = uptimecheckserviceModule.v3.UptimeCheckServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.uptimeCheckServiceStub, undefined); - await client.initialize(); - assert(client.uptimeCheckServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.uptimeCheckServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.uptimeCheckServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - 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); - }); - }); - - describe('getUptimeCheckConfig', () => { - it('invokes getUptimeCheckConfig without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.getUptimeCheckConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getUptimeCheckConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUptimeCheckConfig without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.getUptimeCheckConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getUptimeCheckConfig( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUptimeCheckConfig with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getUptimeCheckConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getUptimeCheckConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUptimeCheckConfig with closed client', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getUptimeCheckConfig(request), expectedError); - }); - }); - - describe('createUptimeCheckConfig', () => { - it('invokes createUptimeCheckConfig without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateUptimeCheckConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.createUptimeCheckConfig = stubSimpleCall(expectedResponse); - const [response] = await client.createUptimeCheckConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUptimeCheckConfig without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateUptimeCheckConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.createUptimeCheckConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createUptimeCheckConfig( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUptimeCheckConfig with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateUptimeCheckConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createUptimeCheckConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createUptimeCheckConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUptimeCheckConfig with closed client', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateUptimeCheckConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createUptimeCheckConfig(request), expectedError); - }); - }); - - describe('updateUptimeCheckConfig', () => { - it('invokes updateUptimeCheckConfig without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateUptimeCheckConfigRequest() - ); - request.uptimeCheckConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateUptimeCheckConfigRequest', ['uptimeCheckConfig', 'name']); - request.uptimeCheckConfig.name = defaultValue1; - const expectedHeaderRequestParams = `uptime_check_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.updateUptimeCheckConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateUptimeCheckConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUptimeCheckConfig without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateUptimeCheckConfigRequest() - ); - request.uptimeCheckConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateUptimeCheckConfigRequest', ['uptimeCheckConfig', 'name']); - request.uptimeCheckConfig.name = defaultValue1; - const expectedHeaderRequestParams = `uptime_check_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.updateUptimeCheckConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateUptimeCheckConfig( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUptimeCheckConfig with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateUptimeCheckConfigRequest() - ); - request.uptimeCheckConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateUptimeCheckConfigRequest', ['uptimeCheckConfig', 'name']); - request.uptimeCheckConfig.name = defaultValue1; - const expectedHeaderRequestParams = `uptime_check_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateUptimeCheckConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateUptimeCheckConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUptimeCheckConfig with closed client', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateUptimeCheckConfigRequest() - ); - request.uptimeCheckConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateUptimeCheckConfigRequest', ['uptimeCheckConfig', 'name']); - request.uptimeCheckConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateUptimeCheckConfig(request), expectedError); - }); - }); - - describe('deleteUptimeCheckConfig', () => { - it('invokes deleteUptimeCheckConfig without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUptimeCheckConfig = stubSimpleCall(expectedResponse); - const [response] = await client.deleteUptimeCheckConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUptimeCheckConfig without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUptimeCheckConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteUptimeCheckConfig( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUptimeCheckConfig with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteUptimeCheckConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteUptimeCheckConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUptimeCheckConfig with closed client', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteUptimeCheckConfig(request), expectedError); - }); - }); - - describe('listUptimeCheckConfigs', () => { - it('invokes listUptimeCheckConfigs without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - ]; - client.innerApiCalls.listUptimeCheckConfigs = stubSimpleCall(expectedResponse); - const [response] = await client.listUptimeCheckConfigs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUptimeCheckConfigs without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - ]; - client.innerApiCalls.listUptimeCheckConfigs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUptimeCheckConfigs( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckConfig[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUptimeCheckConfigs with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listUptimeCheckConfigs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listUptimeCheckConfigs(request), expectedError); - const actualRequest = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUptimeCheckConfigsStream without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - ]; - client.descriptors.page.listUptimeCheckConfigs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listUptimeCheckConfigsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.UptimeCheckConfig[] = []; - stream.on('data', (response: protos.google.monitoring.v3.UptimeCheckConfig) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listUptimeCheckConfigs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUptimeCheckConfigs, request)); - assert( - (client.descriptors.page.listUptimeCheckConfigs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listUptimeCheckConfigsStream with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listUptimeCheckConfigs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listUptimeCheckConfigsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.UptimeCheckConfig[] = []; - stream.on('data', (response: protos.google.monitoring.v3.UptimeCheckConfig) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listUptimeCheckConfigs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUptimeCheckConfigs, request)); - assert( - (client.descriptors.page.listUptimeCheckConfigs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listUptimeCheckConfigs without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - ]; - client.descriptors.page.listUptimeCheckConfigs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IUptimeCheckConfig[] = []; - const iterable = client.listUptimeCheckConfigsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listUptimeCheckConfigs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listUptimeCheckConfigs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listUptimeCheckConfigs with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listUptimeCheckConfigs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listUptimeCheckConfigsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IUptimeCheckConfig[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listUptimeCheckConfigs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listUptimeCheckConfigs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listUptimeCheckIps', () => { - it('invokes listUptimeCheckIps without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - ]; - client.innerApiCalls.listUptimeCheckIps = stubSimpleCall(expectedResponse); - const [response] = await client.listUptimeCheckIps(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUptimeCheckIps without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - ]; - client.innerApiCalls.listUptimeCheckIps = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUptimeCheckIps( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckIp[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUptimeCheckIps with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listUptimeCheckIps = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listUptimeCheckIps(request), expectedError); - }); - - it('invokes listUptimeCheckIpsStream without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - ]; - client.descriptors.page.listUptimeCheckIps.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listUptimeCheckIpsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.UptimeCheckIp[] = []; - stream.on('data', (response: protos.google.monitoring.v3.UptimeCheckIp) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listUptimeCheckIps.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUptimeCheckIps, request)); - }); - - it('invokes listUptimeCheckIpsStream with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUptimeCheckIps.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listUptimeCheckIpsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.UptimeCheckIp[] = []; - stream.on('data', (response: protos.google.monitoring.v3.UptimeCheckIp) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listUptimeCheckIps.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUptimeCheckIps, request)); - }); - - it('uses async iteration with listUptimeCheckIps without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - ]; - client.descriptors.page.listUptimeCheckIps.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IUptimeCheckIp[] = []; - const iterable = client.listUptimeCheckIpsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listUptimeCheckIps.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listUptimeCheckIps with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUptimeCheckIps.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listUptimeCheckIpsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IUptimeCheckIp[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listUptimeCheckIps.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/package.json b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/package.json index df3eec55f353..555427ec9ece 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/package.json @@ -65,12 +65,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -85,21 +79,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/monitoring-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/monitoring/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/monitoring/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/package.json b/core/generator/gapic-generator-typescript/baselines/monitoring/package.json index 8a476819d8c6..8496bdfe5249 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/package.json +++ b/core/generator/gapic-generator-typescript/baselines/monitoring/package.json @@ -35,27 +35,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index fa12b2a66c60..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const monitoring = require('monitoring'); - -function main() { - const alertPolicyServiceClient = new monitoring.AlertPolicyServiceClient(); - const groupServiceClient = new monitoring.GroupServiceClient(); - const metricServiceClient = new monitoring.MetricServiceClient(); - const notificationChannelServiceClient = new monitoring.NotificationChannelServiceClient(); - const serviceMonitoringServiceClient = new monitoring.ServiceMonitoringServiceClient(); - const uptimeCheckServiceClient = new monitoring.UptimeCheckServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 561e2a128649..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {AlertPolicyServiceClient, GroupServiceClient, MetricServiceClient, NotificationChannelServiceClient, ServiceMonitoringServiceClient, UptimeCheckServiceClient} from 'monitoring'; - -// check that the client class type name can be used -function doStuffWithAlertPolicyServiceClient(client: AlertPolicyServiceClient) { - client.close(); -} -function doStuffWithGroupServiceClient(client: GroupServiceClient) { - client.close(); -} -function doStuffWithMetricServiceClient(client: MetricServiceClient) { - client.close(); -} -function doStuffWithNotificationChannelServiceClient(client: NotificationChannelServiceClient) { - client.close(); -} -function doStuffWithServiceMonitoringServiceClient(client: ServiceMonitoringServiceClient) { - client.close(); -} -function doStuffWithUptimeCheckServiceClient(client: UptimeCheckServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const alertPolicyServiceClient = new AlertPolicyServiceClient(); - doStuffWithAlertPolicyServiceClient(alertPolicyServiceClient); - // check that the client instance can be created - const groupServiceClient = new GroupServiceClient(); - doStuffWithGroupServiceClient(groupServiceClient); - // check that the client instance can be created - const metricServiceClient = new MetricServiceClient(); - doStuffWithMetricServiceClient(metricServiceClient); - // check that the client instance can be created - const notificationChannelServiceClient = new NotificationChannelServiceClient(); - doStuffWithNotificationChannelServiceClient(notificationChannelServiceClient); - // check that the client instance can be created - const serviceMonitoringServiceClient = new ServiceMonitoringServiceClient(); - doStuffWithServiceMonitoringServiceClient(serviceMonitoringServiceClient); - // check that the client instance can be created - const uptimeCheckServiceClient = new UptimeCheckServiceClient(); - doStuffWithUptimeCheckServiceClient(uptimeCheckServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_alert_policy_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_alert_policy_service_v3.ts.baseline deleted file mode 100644 index ed8e28969ee3..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_alert_policy_service_v3.ts.baseline +++ /dev/null @@ -1,1905 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as alertpolicyserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.AlertPolicyServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = alertpolicyserviceModule.v3.AlertPolicyServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = alertpolicyserviceModule.v3.AlertPolicyServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new alertpolicyserviceModule.v3.AlertPolicyServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = alertpolicyserviceModule.v3.AlertPolicyServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.alertPolicyServiceStub, undefined); - await client.initialize(); - assert(client.alertPolicyServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.alertPolicyServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.alertPolicyServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - 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); - }); - }); - - describe('getAlertPolicy', () => { - it('invokes getAlertPolicy without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.getAlertPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.getAlertPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertPolicy without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.getAlertPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getAlertPolicy( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IAlertPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertPolicy with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getAlertPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getAlertPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertPolicy with closed client', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getAlertPolicy(request), expectedError); - }); - }); - - describe('createAlertPolicy', () => { - it('invokes createAlertPolicy without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.createAlertPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.createAlertPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createAlertPolicy without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.createAlertPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createAlertPolicy( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IAlertPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createAlertPolicy with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createAlertPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createAlertPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createAlertPolicy with closed client', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createAlertPolicy(request), expectedError); - }); - }); - - describe('deleteAlertPolicy', () => { - it('invokes deleteAlertPolicy without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteAlertPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.deleteAlertPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteAlertPolicy without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteAlertPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteAlertPolicy( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteAlertPolicy with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteAlertPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteAlertPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteAlertPolicy with closed client', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteAlertPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteAlertPolicyRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteAlertPolicy(request), expectedError); - }); - }); - - describe('updateAlertPolicy', () => { - it('invokes updateAlertPolicy without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateAlertPolicyRequest() - ); - request.alertPolicy ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateAlertPolicyRequest', ['alertPolicy', 'name']); - request.alertPolicy.name = defaultValue1; - const expectedHeaderRequestParams = `alert_policy.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.updateAlertPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.updateAlertPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertPolicy without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateAlertPolicyRequest() - ); - request.alertPolicy ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateAlertPolicyRequest', ['alertPolicy', 'name']); - request.alertPolicy.name = defaultValue1; - const expectedHeaderRequestParams = `alert_policy.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.AlertPolicy() - ); - client.innerApiCalls.updateAlertPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateAlertPolicy( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IAlertPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertPolicy with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateAlertPolicyRequest() - ); - request.alertPolicy ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateAlertPolicyRequest', ['alertPolicy', 'name']); - request.alertPolicy.name = defaultValue1; - const expectedHeaderRequestParams = `alert_policy.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateAlertPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateAlertPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertPolicy with closed client', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateAlertPolicyRequest() - ); - request.alertPolicy ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateAlertPolicyRequest', ['alertPolicy', 'name']); - request.alertPolicy.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateAlertPolicy(request), expectedError); - }); - }); - - describe('listAlertPolicies', () => { - it('invokes listAlertPolicies without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - ]; - client.innerApiCalls.listAlertPolicies = stubSimpleCall(expectedResponse); - const [response] = await client.listAlertPolicies(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listAlertPolicies without error using callback', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - ]; - client.innerApiCalls.listAlertPolicies = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listAlertPolicies( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IAlertPolicy[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listAlertPolicies with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listAlertPolicies = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listAlertPolicies(request), expectedError); - const actualRequest = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listAlertPolicies as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listAlertPoliciesStream without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - ]; - client.descriptors.page.listAlertPolicies.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listAlertPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.AlertPolicy[] = []; - stream.on('data', (response: protos.google.monitoring.v3.AlertPolicy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listAlertPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listAlertPolicies, request)); - assert( - (client.descriptors.page.listAlertPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listAlertPoliciesStream with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listAlertPolicies.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listAlertPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.AlertPolicy[] = []; - stream.on('data', (response: protos.google.monitoring.v3.AlertPolicy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listAlertPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listAlertPolicies, request)); - assert( - (client.descriptors.page.listAlertPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listAlertPolicies without error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - generateSampleMessage(new protos.google.monitoring.v3.AlertPolicy()), - ]; - client.descriptors.page.listAlertPolicies.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IAlertPolicy[] = []; - const iterable = client.listAlertPoliciesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listAlertPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listAlertPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listAlertPolicies with error', async () => { - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListAlertPoliciesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListAlertPoliciesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listAlertPolicies.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listAlertPoliciesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IAlertPolicy[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listAlertPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listAlertPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', async () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', async () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', async () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', async () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', async () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', async () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', async () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', async () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', async () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', async () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', async () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', async () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', async () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', async () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', async () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new alertpolicyserviceModule.v3.AlertPolicyServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_group_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_group_service_v3.ts.baseline deleted file mode 100644 index cafd10a8379b..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_group_service_v3.ts.baseline +++ /dev/null @@ -1,2150 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as groupserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.GroupServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new groupserviceModule.v3.GroupServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new groupserviceModule.v3.GroupServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = groupserviceModule.v3.GroupServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = groupserviceModule.v3.GroupServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new groupserviceModule.v3.GroupServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new groupserviceModule.v3.GroupServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new groupserviceModule.v3.GroupServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new groupserviceModule.v3.GroupServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new groupserviceModule.v3.GroupServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = groupserviceModule.v3.GroupServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new groupserviceModule.v3.GroupServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.groupServiceStub, undefined); - await client.initialize(); - assert(client.groupServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.groupServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.groupServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new groupserviceModule.v3.GroupServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new groupserviceModule.v3.GroupServiceClient({ - 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); - }); - }); - - describe('getGroup', () => { - it('invokes getGroup without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.getGroup = stubSimpleCall(expectedResponse); - const [response] = await client.getGroup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGroup without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.getGroup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getGroup( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGroup|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGroup with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getGroup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getGroup(request), expectedError); - const actualRequest = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGroup with closed client', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetGroupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getGroup(request), expectedError); - }); - }); - - describe('createGroup', () => { - it('invokes createGroup without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.createGroup = stubSimpleCall(expectedResponse); - const [response] = await client.createGroup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGroup without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.createGroup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createGroup( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGroup|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGroup with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createGroup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createGroup(request), expectedError); - const actualRequest = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGroup with closed client', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateGroupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createGroup(request), expectedError); - }); - }); - - describe('updateGroup', () => { - it('invokes updateGroup without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateGroupRequest() - ); - request.group ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateGroupRequest', ['group', 'name']); - request.group.name = defaultValue1; - const expectedHeaderRequestParams = `group.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.updateGroup = stubSimpleCall(expectedResponse); - const [response] = await client.updateGroup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGroup without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateGroupRequest() - ); - request.group ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateGroupRequest', ['group', 'name']); - request.group.name = defaultValue1; - const expectedHeaderRequestParams = `group.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Group() - ); - client.innerApiCalls.updateGroup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateGroup( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGroup|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGroup with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateGroupRequest() - ); - request.group ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateGroupRequest', ['group', 'name']); - request.group.name = defaultValue1; - const expectedHeaderRequestParams = `group.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateGroup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateGroup(request), expectedError); - const actualRequest = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGroup with closed client', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateGroupRequest() - ); - request.group ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateGroupRequest', ['group', 'name']); - request.group.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateGroup(request), expectedError); - }); - }); - - describe('deleteGroup', () => { - it('invokes deleteGroup without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteGroup = stubSimpleCall(expectedResponse); - const [response] = await client.deleteGroup(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGroup without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteGroup = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteGroup( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGroup with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteGroupRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteGroup = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteGroup(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGroup as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGroup with closed client', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteGroupRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteGroupRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteGroup(request), expectedError); - }); - }); - - describe('listGroups', () => { - it('invokes listGroups without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - ]; - client.innerApiCalls.listGroups = stubSimpleCall(expectedResponse); - const [response] = await client.listGroups(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroups without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - ]; - client.innerApiCalls.listGroups = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listGroups( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGroup[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroups with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listGroups = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listGroups(request), expectedError); - const actualRequest = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroups as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroupsStream without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - ]; - client.descriptors.page.listGroups.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listGroupsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.Group[] = []; - stream.on('data', (response: protos.google.monitoring.v3.Group) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listGroups.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGroups, request)); - assert( - (client.descriptors.page.listGroups.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listGroupsStream with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGroups.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listGroupsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.Group[] = []; - stream.on('data', (response: protos.google.monitoring.v3.Group) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listGroups.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGroups, request)); - assert( - (client.descriptors.page.listGroups.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGroups without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - generateSampleMessage(new protos.google.monitoring.v3.Group()), - ]; - client.descriptors.page.listGroups.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IGroup[] = []; - const iterable = client.listGroupsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listGroups.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGroups.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGroups with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGroups.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listGroupsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IGroup[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listGroups.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGroups.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listGroupMembers', () => { - it('invokes listGroupMembers without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - ]; - client.innerApiCalls.listGroupMembers = stubSimpleCall(expectedResponse); - const [response] = await client.listGroupMembers(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroupMembers without error using callback', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - ]; - client.innerApiCalls.listGroupMembers = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listGroupMembers( - request, - (err?: Error|null, result?: protos.google.api.IMonitoredResource[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroupMembers with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listGroupMembers = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listGroupMembers(request), expectedError); - const actualRequest = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGroupMembers as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGroupMembersStream without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - ]; - client.descriptors.page.listGroupMembers.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listGroupMembersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResource[] = []; - stream.on('data', (response: protos.google.api.MonitoredResource) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listGroupMembers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGroupMembers, request)); - assert( - (client.descriptors.page.listGroupMembers.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listGroupMembersStream with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGroupMembers.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listGroupMembersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResource[] = []; - stream.on('data', (response: protos.google.api.MonitoredResource) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listGroupMembers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGroupMembers, request)); - assert( - (client.descriptors.page.listGroupMembers.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGroupMembers without error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - generateSampleMessage(new protos.google.api.MonitoredResource()), - ]; - client.descriptors.page.listGroupMembers.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.api.IMonitoredResource[] = []; - const iterable = client.listGroupMembersAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listGroupMembers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGroupMembers.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGroupMembers with error', async () => { - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListGroupMembersRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListGroupMembersRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGroupMembers.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listGroupMembersAsync(request); - await assert.rejects(async () => { - const responses: protos.google.api.IMonitoredResource[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listGroupMembers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGroupMembers.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', async () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', async () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', async () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', async () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', async () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', async () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', async () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', async () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', async () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', async () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', async () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', async () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', async () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', async () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', async () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new groupserviceModule.v3.GroupServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_metric_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_metric_service_v3.ts.baseline deleted file mode 100644 index 931858146bc4..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_metric_service_v3.ts.baseline +++ /dev/null @@ -1,2727 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as metricserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.MetricServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new metricserviceModule.v3.MetricServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new metricserviceModule.v3.MetricServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = metricserviceModule.v3.MetricServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = metricserviceModule.v3.MetricServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new metricserviceModule.v3.MetricServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new metricserviceModule.v3.MetricServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new metricserviceModule.v3.MetricServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new metricserviceModule.v3.MetricServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new metricserviceModule.v3.MetricServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = metricserviceModule.v3.MetricServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new metricserviceModule.v3.MetricServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.metricServiceStub, undefined); - await client.initialize(); - assert(client.metricServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.metricServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.metricServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new metricserviceModule.v3.MetricServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new metricserviceModule.v3.MetricServiceClient({ - 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); - }); - }); - - describe('getMonitoredResourceDescriptor', () => { - it('invokes getMonitoredResourceDescriptor without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMonitoredResourceDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMonitoredResourceDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MonitoredResourceDescriptor() - ); - client.innerApiCalls.getMonitoredResourceDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.getMonitoredResourceDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMonitoredResourceDescriptor without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMonitoredResourceDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMonitoredResourceDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MonitoredResourceDescriptor() - ); - client.innerApiCalls.getMonitoredResourceDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getMonitoredResourceDescriptor( - request, - (err?: Error|null, result?: protos.google.api.IMonitoredResourceDescriptor|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMonitoredResourceDescriptor with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMonitoredResourceDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMonitoredResourceDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getMonitoredResourceDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getMonitoredResourceDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMonitoredResourceDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMonitoredResourceDescriptor with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMonitoredResourceDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMonitoredResourceDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getMonitoredResourceDescriptor(request), expectedError); - }); - }); - - describe('getMetricDescriptor', () => { - it('invokes getMetricDescriptor without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MetricDescriptor() - ); - client.innerApiCalls.getMetricDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.getMetricDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMetricDescriptor without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MetricDescriptor() - ); - client.innerApiCalls.getMetricDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getMetricDescriptor( - request, - (err?: Error|null, result?: protos.google.api.IMetricDescriptor|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMetricDescriptor with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getMetricDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getMetricDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getMetricDescriptor with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getMetricDescriptor(request), expectedError); - }); - }); - - describe('createMetricDescriptor', () => { - it('invokes createMetricDescriptor without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MetricDescriptor() - ); - client.innerApiCalls.createMetricDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.createMetricDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMetricDescriptor without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.MetricDescriptor() - ); - client.innerApiCalls.createMetricDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createMetricDescriptor( - request, - (err?: Error|null, result?: protos.google.api.IMetricDescriptor|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMetricDescriptor with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createMetricDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createMetricDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMetricDescriptor with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createMetricDescriptor(request), expectedError); - }); - }); - - describe('deleteMetricDescriptor', () => { - it('invokes deleteMetricDescriptor without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteMetricDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.deleteMetricDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMetricDescriptor without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteMetricDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteMetricDescriptor( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMetricDescriptor with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteMetricDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteMetricDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMetricDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMetricDescriptor with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteMetricDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteMetricDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteMetricDescriptor(request), expectedError); - }); - }); - - describe('createTimeSeries', () => { - it('invokes createTimeSeries without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.createTimeSeries = stubSimpleCall(expectedResponse); - const [response] = await client.createTimeSeries(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTimeSeries without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.createTimeSeries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createTimeSeries( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTimeSeries with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createTimeSeries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createTimeSeries(request), expectedError); - const actualRequest = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTimeSeries with closed client', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createTimeSeries(request), expectedError); - }); - }); - - describe('listMonitoredResourceDescriptors', () => { - it('invokes listMonitoredResourceDescriptors without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCall(expectedResponse); - const [response] = await client.listMonitoredResourceDescriptors(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMonitoredResourceDescriptors without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listMonitoredResourceDescriptors( - request, - (err?: Error|null, result?: protos.google.api.IMonitoredResourceDescriptor[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMonitoredResourceDescriptors with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listMonitoredResourceDescriptors = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listMonitoredResourceDescriptors(request), expectedError); - const actualRequest = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMonitoredResourceDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMonitoredResourceDescriptorsStream without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.descriptors.page.listMonitoredResourceDescriptors.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listMonitoredResourceDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResourceDescriptor[] = []; - stream.on('data', (response: protos.google.api.MonitoredResourceDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMonitoredResourceDescriptors, request)); - assert( - (client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listMonitoredResourceDescriptorsStream with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listMonitoredResourceDescriptors.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listMonitoredResourceDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MonitoredResourceDescriptor[] = []; - stream.on('data', (response: protos.google.api.MonitoredResourceDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMonitoredResourceDescriptors, request)); - assert( - (client.descriptors.page.listMonitoredResourceDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listMonitoredResourceDescriptors without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - generateSampleMessage(new protos.google.api.MonitoredResourceDescriptor()), - ]; - client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.api.IMonitoredResourceDescriptor[] = []; - const iterable = client.listMonitoredResourceDescriptorsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listMonitoredResourceDescriptors with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listMonitoredResourceDescriptorsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.api.IMonitoredResourceDescriptor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listMonitoredResourceDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listMetricDescriptors', () => { - it('invokes listMetricDescriptors without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - ]; - client.innerApiCalls.listMetricDescriptors = stubSimpleCall(expectedResponse); - const [response] = await client.listMetricDescriptors(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMetricDescriptors without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - ]; - client.innerApiCalls.listMetricDescriptors = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listMetricDescriptors( - request, - (err?: Error|null, result?: protos.google.api.IMetricDescriptor[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMetricDescriptors with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listMetricDescriptors = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listMetricDescriptors(request), expectedError); - const actualRequest = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMetricDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMetricDescriptorsStream without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - ]; - client.descriptors.page.listMetricDescriptors.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listMetricDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MetricDescriptor[] = []; - stream.on('data', (response: protos.google.api.MetricDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listMetricDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMetricDescriptors, request)); - assert( - (client.descriptors.page.listMetricDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listMetricDescriptorsStream with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listMetricDescriptors.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listMetricDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.api.MetricDescriptor[] = []; - stream.on('data', (response: protos.google.api.MetricDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listMetricDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listMetricDescriptors, request)); - assert( - (client.descriptors.page.listMetricDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listMetricDescriptors without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - generateSampleMessage(new protos.google.api.MetricDescriptor()), - ]; - client.descriptors.page.listMetricDescriptors.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.api.IMetricDescriptor[] = []; - const iterable = client.listMetricDescriptorsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listMetricDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listMetricDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listMetricDescriptors with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListMetricDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListMetricDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listMetricDescriptors.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listMetricDescriptorsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.api.IMetricDescriptor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listMetricDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listMetricDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listTimeSeries', () => { - it('invokes listTimeSeries without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - ]; - client.innerApiCalls.listTimeSeries = stubSimpleCall(expectedResponse); - const [response] = await client.listTimeSeries(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTimeSeries without error using callback', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - ]; - client.innerApiCalls.listTimeSeries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTimeSeries( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.ITimeSeries[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTimeSeries with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTimeSeries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTimeSeries(request), expectedError); - const actualRequest = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTimeSeries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTimeSeriesStream without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - ]; - client.descriptors.page.listTimeSeries.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTimeSeriesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.TimeSeries[] = []; - stream.on('data', (response: protos.google.monitoring.v3.TimeSeries) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTimeSeries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTimeSeries, request)); - assert( - (client.descriptors.page.listTimeSeries.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTimeSeriesStream with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTimeSeries.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTimeSeriesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.TimeSeries[] = []; - stream.on('data', (response: protos.google.monitoring.v3.TimeSeries) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTimeSeries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTimeSeries, request)); - assert( - (client.descriptors.page.listTimeSeries.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTimeSeries without error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - generateSampleMessage(new protos.google.monitoring.v3.TimeSeries()), - ]; - client.descriptors.page.listTimeSeries.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.ITimeSeries[] = []; - const iterable = client.listTimeSeriesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTimeSeries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTimeSeries.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTimeSeries with error', async () => { - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListTimeSeriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListTimeSeriesRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTimeSeries.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTimeSeriesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.ITimeSeries[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTimeSeries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTimeSeries.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', async () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', async () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', async () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderMetricDescriptor', async () => { - const fakePath = "/rendered/path/folderMetricDescriptor"; - const expectedParameters = { - folder: "folderValue", - metric_descriptor: "metricDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderMetricDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderMetricDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderMetricDescriptorPath', () => { - const result = client.folderMetricDescriptorPath("folderValue", "metricDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderMetricDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderMetricDescriptorName', () => { - const result = client.matchFolderFromFolderMetricDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricDescriptorFromFolderMetricDescriptorName', () => { - const result = client.matchMetricDescriptorFromFolderMetricDescriptorName(fakePath); - assert.strictEqual(result, "metricDescriptorValue"); - assert((client.pathTemplates.folderMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderMonitoredResourceDescriptor', async () => { - const fakePath = "/rendered/path/folderMonitoredResourceDescriptor"; - const expectedParameters = { - folder: "folderValue", - monitored_resource_descriptor: "monitoredResourceDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderMonitoredResourceDescriptorPath', () => { - const result = client.folderMonitoredResourceDescriptorPath("folderValue", "monitoredResourceDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderMonitoredResourceDescriptorName', () => { - const result = client.matchFolderFromFolderMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMonitoredResourceDescriptorFromFolderMonitoredResourceDescriptorName', () => { - const result = client.matchMonitoredResourceDescriptorFromFolderMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "monitoredResourceDescriptorValue"); - assert((client.pathTemplates.folderMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', async () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', async () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', async () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', async () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', async () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationMetricDescriptor', async () => { - const fakePath = "/rendered/path/organizationMetricDescriptor"; - const expectedParameters = { - organization: "organizationValue", - metric_descriptor: "metricDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationMetricDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationMetricDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationMetricDescriptorPath', () => { - const result = client.organizationMetricDescriptorPath("organizationValue", "metricDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationMetricDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationMetricDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationMetricDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricDescriptorFromOrganizationMetricDescriptorName', () => { - const result = client.matchMetricDescriptorFromOrganizationMetricDescriptorName(fakePath); - assert.strictEqual(result, "metricDescriptorValue"); - assert((client.pathTemplates.organizationMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationMonitoredResourceDescriptor', async () => { - const fakePath = "/rendered/path/organizationMonitoredResourceDescriptor"; - const expectedParameters = { - organization: "organizationValue", - monitored_resource_descriptor: "monitoredResourceDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationMonitoredResourceDescriptorPath', () => { - const result = client.organizationMonitoredResourceDescriptorPath("organizationValue", "monitoredResourceDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationMonitoredResourceDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMonitoredResourceDescriptorFromOrganizationMonitoredResourceDescriptorName', () => { - const result = client.matchMonitoredResourceDescriptorFromOrganizationMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "monitoredResourceDescriptorValue"); - assert((client.pathTemplates.organizationMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', async () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', async () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', async () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', async () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', async () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectMetricDescriptor', async () => { - const fakePath = "/rendered/path/projectMetricDescriptor"; - const expectedParameters = { - project: "projectValue", - metric_descriptor: "metricDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectMetricDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectMetricDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectMetricDescriptorPath', () => { - const result = client.projectMetricDescriptorPath("projectValue", "metricDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectMetricDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectMetricDescriptorName', () => { - const result = client.matchProjectFromProjectMetricDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMetricDescriptorFromProjectMetricDescriptorName', () => { - const result = client.matchMetricDescriptorFromProjectMetricDescriptorName(fakePath); - assert.strictEqual(result, "metricDescriptorValue"); - assert((client.pathTemplates.projectMetricDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectMonitoredResourceDescriptor', async () => { - const fakePath = "/rendered/path/projectMonitoredResourceDescriptor"; - const expectedParameters = { - project: "projectValue", - monitored_resource_descriptor: "monitoredResourceDescriptorValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectMonitoredResourceDescriptorPath', () => { - const result = client.projectMonitoredResourceDescriptorPath("projectValue", "monitoredResourceDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectMonitoredResourceDescriptorName', () => { - const result = client.matchProjectFromProjectMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMonitoredResourceDescriptorFromProjectMonitoredResourceDescriptorName', () => { - const result = client.matchMonitoredResourceDescriptorFromProjectMonitoredResourceDescriptorName(fakePath); - assert.strictEqual(result, "monitoredResourceDescriptorValue"); - assert((client.pathTemplates.projectMonitoredResourceDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', async () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', async () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new metricserviceModule.v3.MetricServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_notification_channel_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_notification_channel_service_v3.ts.baseline deleted file mode 100644 index 774957e9ee8d..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_notification_channel_service_v3.ts.baseline +++ /dev/null @@ -1,2582 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as notificationchannelserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.NotificationChannelServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = notificationchannelserviceModule.v3.NotificationChannelServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = notificationchannelserviceModule.v3.NotificationChannelServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new notificationchannelserviceModule.v3.NotificationChannelServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = notificationchannelserviceModule.v3.NotificationChannelServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.notificationChannelServiceStub, undefined); - await client.initialize(); - assert(client.notificationChannelServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.notificationChannelServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.notificationChannelServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - 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); - }); - }); - - describe('getNotificationChannelDescriptor', () => { - it('invokes getNotificationChannelDescriptor without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannelDescriptor() - ); - client.innerApiCalls.getNotificationChannelDescriptor = stubSimpleCall(expectedResponse); - const [response] = await client.getNotificationChannelDescriptor(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelDescriptor without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannelDescriptor() - ); - client.innerApiCalls.getNotificationChannelDescriptor = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getNotificationChannelDescriptor( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannelDescriptor|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelDescriptor with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getNotificationChannelDescriptor = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getNotificationChannelDescriptor(request), expectedError); - const actualRequest = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelDescriptor as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelDescriptor with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelDescriptorRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelDescriptorRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getNotificationChannelDescriptor(request), expectedError); - }); - }); - - describe('getNotificationChannel', () => { - it('invokes getNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.getNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.getNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.getNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getNotificationChannel( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getNotificationChannel(request), expectedError); - }); - }); - - describe('createNotificationChannel', () => { - it('invokes createNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.createNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.createNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.createNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createNotificationChannel( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createNotificationChannel(request), expectedError); - }); - }); - - describe('updateNotificationChannel', () => { - it('invokes updateNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateNotificationChannelRequest() - ); - request.notificationChannel ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateNotificationChannelRequest', ['notificationChannel', 'name']); - request.notificationChannel.name = defaultValue1; - const expectedHeaderRequestParams = `notification_channel.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.updateNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.updateNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateNotificationChannelRequest() - ); - request.notificationChannel ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateNotificationChannelRequest', ['notificationChannel', 'name']); - request.notificationChannel.name = defaultValue1; - const expectedHeaderRequestParams = `notification_channel.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.updateNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateNotificationChannel( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateNotificationChannelRequest() - ); - request.notificationChannel ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateNotificationChannelRequest', ['notificationChannel', 'name']); - request.notificationChannel.name = defaultValue1; - const expectedHeaderRequestParams = `notification_channel.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateNotificationChannelRequest() - ); - request.notificationChannel ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateNotificationChannelRequest', ['notificationChannel', 'name']); - request.notificationChannel.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateNotificationChannel(request), expectedError); - }); - }); - - describe('deleteNotificationChannel', () => { - it('invokes deleteNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.deleteNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteNotificationChannel( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteNotificationChannel(request), expectedError); - }); - }); - - describe('sendNotificationChannelVerificationCode', () => { - it('invokes sendNotificationChannelVerificationCode without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.sendNotificationChannelVerificationCode = stubSimpleCall(expectedResponse); - const [response] = await client.sendNotificationChannelVerificationCode(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes sendNotificationChannelVerificationCode without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.sendNotificationChannelVerificationCode = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.sendNotificationChannelVerificationCode( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes sendNotificationChannelVerificationCode with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.sendNotificationChannelVerificationCode = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.sendNotificationChannelVerificationCode(request), expectedError); - const actualRequest = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.sendNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes sendNotificationChannelVerificationCode with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.SendNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.sendNotificationChannelVerificationCode(request), expectedError); - }); - }); - - describe('getNotificationChannelVerificationCode', () => { - it('invokes getNotificationChannelVerificationCode without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeResponse() - ); - client.innerApiCalls.getNotificationChannelVerificationCode = stubSimpleCall(expectedResponse); - const [response] = await client.getNotificationChannelVerificationCode(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelVerificationCode without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeResponse() - ); - client.innerApiCalls.getNotificationChannelVerificationCode = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getNotificationChannelVerificationCode( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IGetNotificationChannelVerificationCodeResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelVerificationCode with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getNotificationChannelVerificationCode = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getNotificationChannelVerificationCode(request), expectedError); - const actualRequest = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getNotificationChannelVerificationCode as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getNotificationChannelVerificationCode with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetNotificationChannelVerificationCodeRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getNotificationChannelVerificationCode(request), expectedError); - }); - }); - - describe('verifyNotificationChannel', () => { - it('invokes verifyNotificationChannel without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.VerifyNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.VerifyNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.verifyNotificationChannel = stubSimpleCall(expectedResponse); - const [response] = await client.verifyNotificationChannel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyNotificationChannel without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.VerifyNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.VerifyNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.NotificationChannel() - ); - client.innerApiCalls.verifyNotificationChannel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyNotificationChannel( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyNotificationChannel with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.VerifyNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.VerifyNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.verifyNotificationChannel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyNotificationChannel(request), expectedError); - const actualRequest = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyNotificationChannel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyNotificationChannel with closed client', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.VerifyNotificationChannelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.VerifyNotificationChannelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyNotificationChannel(request), expectedError); - }); - }); - - describe('listNotificationChannelDescriptors', () => { - it('invokes listNotificationChannelDescriptors without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - ]; - client.innerApiCalls.listNotificationChannelDescriptors = stubSimpleCall(expectedResponse); - const [response] = await client.listNotificationChannelDescriptors(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannelDescriptors without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - ]; - client.innerApiCalls.listNotificationChannelDescriptors = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listNotificationChannelDescriptors( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannelDescriptor[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannelDescriptors with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listNotificationChannelDescriptors = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listNotificationChannelDescriptors(request), expectedError); - const actualRequest = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannelDescriptors as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannelDescriptorsStream without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - ]; - client.descriptors.page.listNotificationChannelDescriptors.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listNotificationChannelDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.NotificationChannelDescriptor[] = []; - stream.on('data', (response: protos.google.monitoring.v3.NotificationChannelDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listNotificationChannelDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listNotificationChannelDescriptors, request)); - assert( - (client.descriptors.page.listNotificationChannelDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listNotificationChannelDescriptorsStream with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listNotificationChannelDescriptors.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listNotificationChannelDescriptorsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.NotificationChannelDescriptor[] = []; - stream.on('data', (response: protos.google.monitoring.v3.NotificationChannelDescriptor) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listNotificationChannelDescriptors.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listNotificationChannelDescriptors, request)); - assert( - (client.descriptors.page.listNotificationChannelDescriptors.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listNotificationChannelDescriptors without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannelDescriptor()), - ]; - client.descriptors.page.listNotificationChannelDescriptors.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.INotificationChannelDescriptor[] = []; - const iterable = client.listNotificationChannelDescriptorsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listNotificationChannelDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listNotificationChannelDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listNotificationChannelDescriptors with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelDescriptorsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelDescriptorsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listNotificationChannelDescriptors.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listNotificationChannelDescriptorsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.INotificationChannelDescriptor[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listNotificationChannelDescriptors.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listNotificationChannelDescriptors.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listNotificationChannels', () => { - it('invokes listNotificationChannels without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - ]; - client.innerApiCalls.listNotificationChannels = stubSimpleCall(expectedResponse); - const [response] = await client.listNotificationChannels(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannels without error using callback', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - ]; - client.innerApiCalls.listNotificationChannels = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listNotificationChannels( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.INotificationChannel[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannels with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listNotificationChannels = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listNotificationChannels(request), expectedError); - const actualRequest = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listNotificationChannels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listNotificationChannelsStream without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - ]; - client.descriptors.page.listNotificationChannels.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listNotificationChannelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.NotificationChannel[] = []; - stream.on('data', (response: protos.google.monitoring.v3.NotificationChannel) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listNotificationChannels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listNotificationChannels, request)); - assert( - (client.descriptors.page.listNotificationChannels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listNotificationChannelsStream with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listNotificationChannels.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listNotificationChannelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.NotificationChannel[] = []; - stream.on('data', (response: protos.google.monitoring.v3.NotificationChannel) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listNotificationChannels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listNotificationChannels, request)); - assert( - (client.descriptors.page.listNotificationChannels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listNotificationChannels without error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - generateSampleMessage(new protos.google.monitoring.v3.NotificationChannel()), - ]; - client.descriptors.page.listNotificationChannels.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.INotificationChannel[] = []; - const iterable = client.listNotificationChannelsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listNotificationChannels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listNotificationChannels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listNotificationChannels with error', async () => { - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListNotificationChannelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListNotificationChannelsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listNotificationChannels.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listNotificationChannelsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.INotificationChannel[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listNotificationChannels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listNotificationChannels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', async () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', async () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', async () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', async () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', async () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', async () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', async () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', async () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', async () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', async () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', async () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', async () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', async () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', async () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', async () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new notificationchannelserviceModule.v3.NotificationChannelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_service_monitoring_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_service_monitoring_service_v3.ts.baseline deleted file mode 100644 index 27437ecc6284..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_service_monitoring_service_v3.ts.baseline +++ /dev/null @@ -1,2586 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as servicemonitoringserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.ServiceMonitoringServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.serviceMonitoringServiceStub, undefined); - await client.initialize(); - assert(client.serviceMonitoringServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.serviceMonitoringServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.serviceMonitoringServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - 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); - }); - }); - - describe('createService', () => { - it('invokes createService without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.createService = stubSimpleCall(expectedResponse); - const [response] = await client.createService(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createService without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.createService = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createService( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IService|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createService with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createService = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createService(request), expectedError); - const actualRequest = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createService with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createService(request), expectedError); - }); - }); - - describe('getService', () => { - it('invokes getService without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.getService = stubSimpleCall(expectedResponse); - const [response] = await client.getService(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getService without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.getService = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getService( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IService|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getService with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getService = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getService(request), expectedError); - const actualRequest = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getService with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getService(request), expectedError); - }); - }); - - describe('updateService', () => { - it('invokes updateService without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceRequest() - ); - request.service ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceRequest', ['service', 'name']); - request.service.name = defaultValue1; - const expectedHeaderRequestParams = `service.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.updateService = stubSimpleCall(expectedResponse); - const [response] = await client.updateService(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateService without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceRequest() - ); - request.service ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceRequest', ['service', 'name']); - request.service.name = defaultValue1; - const expectedHeaderRequestParams = `service.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.Service() - ); - client.innerApiCalls.updateService = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateService( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IService|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateService with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceRequest() - ); - request.service ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceRequest', ['service', 'name']); - request.service.name = defaultValue1; - const expectedHeaderRequestParams = `service.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateService = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateService(request), expectedError); - const actualRequest = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateService with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceRequest() - ); - request.service ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceRequest', ['service', 'name']); - request.service.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateService(request), expectedError); - }); - }); - - describe('deleteService', () => { - it('invokes deleteService without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteService = stubSimpleCall(expectedResponse); - const [response] = await client.deleteService(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteService without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteService = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteService( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteService with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteService = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteService(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteService as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteService with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteService(request), expectedError); - }); - }); - - describe('createServiceLevelObjective', () => { - it('invokes createServiceLevelObjective without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceLevelObjectiveRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.createServiceLevelObjective = stubSimpleCall(expectedResponse); - const [response] = await client.createServiceLevelObjective(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServiceLevelObjective without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceLevelObjectiveRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.createServiceLevelObjective = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createServiceLevelObjective( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IServiceLevelObjective|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServiceLevelObjective with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceLevelObjectiveRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createServiceLevelObjective = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createServiceLevelObjective(request), expectedError); - const actualRequest = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServiceLevelObjective with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateServiceLevelObjectiveRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createServiceLevelObjective(request), expectedError); - }); - }); - - describe('getServiceLevelObjective', () => { - it('invokes getServiceLevelObjective without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.getServiceLevelObjective = stubSimpleCall(expectedResponse); - const [response] = await client.getServiceLevelObjective(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceLevelObjective without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.getServiceLevelObjective = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getServiceLevelObjective( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IServiceLevelObjective|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceLevelObjective with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getServiceLevelObjective = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getServiceLevelObjective(request), expectedError); - const actualRequest = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServiceLevelObjective with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getServiceLevelObjective(request), expectedError); - }); - }); - - describe('updateServiceLevelObjective', () => { - it('invokes updateServiceLevelObjective without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceLevelObjectiveRequest() - ); - request.serviceLevelObjective ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceLevelObjectiveRequest', ['serviceLevelObjective', 'name']); - request.serviceLevelObjective.name = defaultValue1; - const expectedHeaderRequestParams = `service_level_objective.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.updateServiceLevelObjective = stubSimpleCall(expectedResponse); - const [response] = await client.updateServiceLevelObjective(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServiceLevelObjective without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceLevelObjectiveRequest() - ); - request.serviceLevelObjective ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceLevelObjectiveRequest', ['serviceLevelObjective', 'name']); - request.serviceLevelObjective.name = defaultValue1; - const expectedHeaderRequestParams = `service_level_objective.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.ServiceLevelObjective() - ); - client.innerApiCalls.updateServiceLevelObjective = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateServiceLevelObjective( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IServiceLevelObjective|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServiceLevelObjective with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceLevelObjectiveRequest() - ); - request.serviceLevelObjective ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceLevelObjectiveRequest', ['serviceLevelObjective', 'name']); - request.serviceLevelObjective.name = defaultValue1; - const expectedHeaderRequestParams = `service_level_objective.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateServiceLevelObjective = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateServiceLevelObjective(request), expectedError); - const actualRequest = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServiceLevelObjective with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateServiceLevelObjectiveRequest() - ); - request.serviceLevelObjective ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateServiceLevelObjectiveRequest', ['serviceLevelObjective', 'name']); - request.serviceLevelObjective.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateServiceLevelObjective(request), expectedError); - }); - }); - - describe('deleteServiceLevelObjective', () => { - it('invokes deleteServiceLevelObjective without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteServiceLevelObjective = stubSimpleCall(expectedResponse); - const [response] = await client.deleteServiceLevelObjective(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServiceLevelObjective without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteServiceLevelObjective = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteServiceLevelObjective( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServiceLevelObjective with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteServiceLevelObjective = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteServiceLevelObjective(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServiceLevelObjective as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServiceLevelObjective with closed client', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteServiceLevelObjectiveRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteServiceLevelObjectiveRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteServiceLevelObjective(request), expectedError); - }); - }); - - describe('listServices', () => { - it('invokes listServices without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - ]; - client.innerApiCalls.listServices = stubSimpleCall(expectedResponse); - const [response] = await client.listServices(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServices without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - ]; - client.innerApiCalls.listServices = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServices( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IService[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServices with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServices = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServices(request), expectedError); - const actualRequest = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServices as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServicesStream without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - ]; - client.descriptors.page.listServices.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listServicesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.Service[] = []; - stream.on('data', (response: protos.google.monitoring.v3.Service) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServices, request)); - assert( - (client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listServicesStream with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServices.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listServicesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.Service[] = []; - stream.on('data', (response: protos.google.monitoring.v3.Service) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServices, request)); - assert( - (client.descriptors.page.listServices.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServices without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - generateSampleMessage(new protos.google.monitoring.v3.Service()), - ]; - client.descriptors.page.listServices.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IService[] = []; - const iterable = client.listServicesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listServices.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServices.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServices with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServicesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServicesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServices.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listServicesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IService[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listServices.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServices.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listServiceLevelObjectives', () => { - it('invokes listServiceLevelObjectives without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - ]; - client.innerApiCalls.listServiceLevelObjectives = stubSimpleCall(expectedResponse); - const [response] = await client.listServiceLevelObjectives(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServiceLevelObjectives without error using callback', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - ]; - client.innerApiCalls.listServiceLevelObjectives = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServiceLevelObjectives( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IServiceLevelObjective[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServiceLevelObjectives with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServiceLevelObjectives = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServiceLevelObjectives(request), expectedError); - const actualRequest = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServiceLevelObjectives as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServiceLevelObjectivesStream without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - ]; - client.descriptors.page.listServiceLevelObjectives.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listServiceLevelObjectivesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.ServiceLevelObjective[] = []; - stream.on('data', (response: protos.google.monitoring.v3.ServiceLevelObjective) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listServiceLevelObjectives.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServiceLevelObjectives, request)); - assert( - (client.descriptors.page.listServiceLevelObjectives.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listServiceLevelObjectivesStream with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServiceLevelObjectives.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listServiceLevelObjectivesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.ServiceLevelObjective[] = []; - stream.on('data', (response: protos.google.monitoring.v3.ServiceLevelObjective) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listServiceLevelObjectives.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServiceLevelObjectives, request)); - assert( - (client.descriptors.page.listServiceLevelObjectives.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServiceLevelObjectives without error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - generateSampleMessage(new protos.google.monitoring.v3.ServiceLevelObjective()), - ]; - client.descriptors.page.listServiceLevelObjectives.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IServiceLevelObjective[] = []; - const iterable = client.listServiceLevelObjectivesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listServiceLevelObjectives.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServiceLevelObjectives.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServiceLevelObjectives with error', async () => { - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListServiceLevelObjectivesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListServiceLevelObjectivesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServiceLevelObjectives.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listServiceLevelObjectivesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IServiceLevelObjective[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listServiceLevelObjectives.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServiceLevelObjectives.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', async () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', async () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', async () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', async () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', async () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', async () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', async () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', async () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', async () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', async () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', async () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', async () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', async () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', async () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', async () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new servicemonitoringserviceModule.v3.ServiceMonitoringServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_uptime_check_service_v3.ts.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_uptime_check_service_v3.ts.baseline deleted file mode 100644 index 4893feec487c..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/test/gapic_uptime_check_service_v3.ts.baseline +++ /dev/null @@ -1,2080 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as uptimecheckserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3.UptimeCheckServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = uptimecheckserviceModule.v3.UptimeCheckServiceClient.servicePath; - assert.strictEqual(servicePath, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = uptimecheckserviceModule.v3.UptimeCheckServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'monitoring.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'monitoring.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new uptimecheckserviceModule.v3.UptimeCheckServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = uptimecheckserviceModule.v3.UptimeCheckServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.uptimeCheckServiceStub, undefined); - await client.initialize(); - assert(client.uptimeCheckServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.uptimeCheckServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.uptimeCheckServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - 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); - }); - }); - - describe('getUptimeCheckConfig', () => { - it('invokes getUptimeCheckConfig without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.getUptimeCheckConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getUptimeCheckConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUptimeCheckConfig without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.getUptimeCheckConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getUptimeCheckConfig( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUptimeCheckConfig with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getUptimeCheckConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getUptimeCheckConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUptimeCheckConfig with closed client', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.GetUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.GetUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getUptimeCheckConfig(request), expectedError); - }); - }); - - describe('createUptimeCheckConfig', () => { - it('invokes createUptimeCheckConfig without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateUptimeCheckConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.createUptimeCheckConfig = stubSimpleCall(expectedResponse); - const [response] = await client.createUptimeCheckConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUptimeCheckConfig without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateUptimeCheckConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.createUptimeCheckConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createUptimeCheckConfig( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUptimeCheckConfig with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateUptimeCheckConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createUptimeCheckConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createUptimeCheckConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createUptimeCheckConfig with closed client', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.CreateUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.CreateUptimeCheckConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createUptimeCheckConfig(request), expectedError); - }); - }); - - describe('updateUptimeCheckConfig', () => { - it('invokes updateUptimeCheckConfig without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateUptimeCheckConfigRequest() - ); - request.uptimeCheckConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateUptimeCheckConfigRequest', ['uptimeCheckConfig', 'name']); - request.uptimeCheckConfig.name = defaultValue1; - const expectedHeaderRequestParams = `uptime_check_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.updateUptimeCheckConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateUptimeCheckConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUptimeCheckConfig without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateUptimeCheckConfigRequest() - ); - request.uptimeCheckConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateUptimeCheckConfigRequest', ['uptimeCheckConfig', 'name']); - request.uptimeCheckConfig.name = defaultValue1; - const expectedHeaderRequestParams = `uptime_check_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.monitoring.v3.UptimeCheckConfig() - ); - client.innerApiCalls.updateUptimeCheckConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateUptimeCheckConfig( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUptimeCheckConfig with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateUptimeCheckConfigRequest() - ); - request.uptimeCheckConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateUptimeCheckConfigRequest', ['uptimeCheckConfig', 'name']); - request.uptimeCheckConfig.name = defaultValue1; - const expectedHeaderRequestParams = `uptime_check_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateUptimeCheckConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateUptimeCheckConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUptimeCheckConfig with closed client', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.UpdateUptimeCheckConfigRequest() - ); - request.uptimeCheckConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.UpdateUptimeCheckConfigRequest', ['uptimeCheckConfig', 'name']); - request.uptimeCheckConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateUptimeCheckConfig(request), expectedError); - }); - }); - - describe('deleteUptimeCheckConfig', () => { - it('invokes deleteUptimeCheckConfig without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUptimeCheckConfig = stubSimpleCall(expectedResponse); - const [response] = await client.deleteUptimeCheckConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUptimeCheckConfig without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUptimeCheckConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteUptimeCheckConfig( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUptimeCheckConfig with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteUptimeCheckConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteUptimeCheckConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUptimeCheckConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUptimeCheckConfig with closed client', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.DeleteUptimeCheckConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.DeleteUptimeCheckConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteUptimeCheckConfig(request), expectedError); - }); - }); - - describe('listUptimeCheckConfigs', () => { - it('invokes listUptimeCheckConfigs without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - ]; - client.innerApiCalls.listUptimeCheckConfigs = stubSimpleCall(expectedResponse); - const [response] = await client.listUptimeCheckConfigs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUptimeCheckConfigs without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - ]; - client.innerApiCalls.listUptimeCheckConfigs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUptimeCheckConfigs( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckConfig[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUptimeCheckConfigs with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listUptimeCheckConfigs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listUptimeCheckConfigs(request), expectedError); - const actualRequest = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listUptimeCheckConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listUptimeCheckConfigsStream without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - ]; - client.descriptors.page.listUptimeCheckConfigs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listUptimeCheckConfigsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.UptimeCheckConfig[] = []; - stream.on('data', (response: protos.google.monitoring.v3.UptimeCheckConfig) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listUptimeCheckConfigs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUptimeCheckConfigs, request)); - assert( - (client.descriptors.page.listUptimeCheckConfigs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listUptimeCheckConfigsStream with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listUptimeCheckConfigs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listUptimeCheckConfigsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.UptimeCheckConfig[] = []; - stream.on('data', (response: protos.google.monitoring.v3.UptimeCheckConfig) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listUptimeCheckConfigs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUptimeCheckConfigs, request)); - assert( - (client.descriptors.page.listUptimeCheckConfigs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listUptimeCheckConfigs without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckConfig()), - ]; - client.descriptors.page.listUptimeCheckConfigs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IUptimeCheckConfig[] = []; - const iterable = client.listUptimeCheckConfigsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listUptimeCheckConfigs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listUptimeCheckConfigs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listUptimeCheckConfigs with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.monitoring.v3.ListUptimeCheckConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listUptimeCheckConfigs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listUptimeCheckConfigsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IUptimeCheckConfig[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listUptimeCheckConfigs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listUptimeCheckConfigs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listUptimeCheckIps', () => { - it('invokes listUptimeCheckIps without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - ]; - client.innerApiCalls.listUptimeCheckIps = stubSimpleCall(expectedResponse); - const [response] = await client.listUptimeCheckIps(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUptimeCheckIps without error using callback', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - ]; - client.innerApiCalls.listUptimeCheckIps = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUptimeCheckIps( - request, - (err?: Error|null, result?: protos.google.monitoring.v3.IUptimeCheckIp[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUptimeCheckIps with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listUptimeCheckIps = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listUptimeCheckIps(request), expectedError); - }); - - it('invokes listUptimeCheckIpsStream without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - ]; - client.descriptors.page.listUptimeCheckIps.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listUptimeCheckIpsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.UptimeCheckIp[] = []; - stream.on('data', (response: protos.google.monitoring.v3.UptimeCheckIp) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listUptimeCheckIps.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUptimeCheckIps, request)); - }); - - it('invokes listUptimeCheckIpsStream with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUptimeCheckIps.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listUptimeCheckIpsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.monitoring.v3.UptimeCheckIp[] = []; - stream.on('data', (response: protos.google.monitoring.v3.UptimeCheckIp) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listUptimeCheckIps.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUptimeCheckIps, request)); - }); - - it('uses async iteration with listUptimeCheckIps without error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - generateSampleMessage(new protos.google.monitoring.v3.UptimeCheckIp()), - ]; - client.descriptors.page.listUptimeCheckIps.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.monitoring.v3.IUptimeCheckIp[] = []; - const iterable = client.listUptimeCheckIpsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listUptimeCheckIps.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listUptimeCheckIps with error', async () => { - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.monitoring.v3.ListUptimeCheckIpsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUptimeCheckIps.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listUptimeCheckIpsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.monitoring.v3.IUptimeCheckIp[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listUptimeCheckIps.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('folderAlertPolicy', async () => { - const fakePath = "/rendered/path/folderAlertPolicy"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyPath', () => { - const result = client.folderAlertPolicyPath("folderValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyName', () => { - const result = client.matchFolderFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/folderAlertPolicyCondition"; - const expectedParameters = { - folder: "folderValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderAlertPolicyConditionPath', () => { - const result = client.folderAlertPolicyConditionPath("folderValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderAlertPolicyConditionName', () => { - const result = client.matchFolderFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromFolderAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromFolderAlertPolicyConditionName', () => { - const result = client.matchConditionFromFolderAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.folderAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderChannelDescriptor', async () => { - const fakePath = "/rendered/path/folderChannelDescriptor"; - const expectedParameters = { - folder: "folderValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderChannelDescriptorPath', () => { - const result = client.folderChannelDescriptorPath("folderValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderChannelDescriptorName', () => { - const result = client.matchFolderFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromFolderChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromFolderChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.folderChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderGroup', async () => { - const fakePath = "/rendered/path/folderGroup"; - const expectedParameters = { - folder: "folderValue", - group: "groupValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderGroupPath', () => { - const result = client.folderGroupPath("folderValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderGroupName', () => { - const result = client.matchFolderFromFolderGroupName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromFolderGroupName', () => { - const result = client.matchGroupFromFolderGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.folderGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderNotificationChannel', async () => { - const fakePath = "/rendered/path/folderNotificationChannel"; - const expectedParameters = { - folder: "folderValue", - notification_channel: "notificationChannelValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderNotificationChannelPath', () => { - const result = client.folderNotificationChannelPath("folderValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderNotificationChannelName', () => { - const result = client.matchFolderFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromFolderNotificationChannelName', () => { - const result = client.matchNotificationChannelFromFolderNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.folderNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderService', async () => { - const fakePath = "/rendered/path/folderService"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServicePath', () => { - const result = client.folderServicePath("folderValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceName', () => { - const result = client.matchFolderFromFolderServiceName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceName', () => { - const result = client.matchServiceFromFolderServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/folderServiceServiceLevelObjective"; - const expectedParameters = { - folder: "folderValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderServiceServiceLevelObjectivePath', () => { - const result = client.folderServiceServiceLevelObjectivePath("folderValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchFolderFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromFolderServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.folderServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/folderUptimeCheckConfig"; - const expectedParameters = { - folder: "folderValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderUptimeCheckConfigPath', () => { - const result = client.folderUptimeCheckConfigPath("folderValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderUptimeCheckConfigName', () => { - const result = client.matchFolderFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromFolderUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromFolderUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.folderUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicy', async () => { - const fakePath = "/rendered/path/organizationAlertPolicy"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyPath', () => { - const result = client.organizationAlertPolicyPath("organizationValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/organizationAlertPolicyCondition"; - const expectedParameters = { - organization: "organizationValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationAlertPolicyConditionPath', () => { - const result = client.organizationAlertPolicyConditionPath("organizationValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchOrganizationFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromOrganizationAlertPolicyConditionName', () => { - const result = client.matchConditionFromOrganizationAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.organizationAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationChannelDescriptor', async () => { - const fakePath = "/rendered/path/organizationChannelDescriptor"; - const expectedParameters = { - organization: "organizationValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationChannelDescriptorPath', () => { - const result = client.organizationChannelDescriptorPath("organizationValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationChannelDescriptorName', () => { - const result = client.matchOrganizationFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromOrganizationChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromOrganizationChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.organizationChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationGroup', async () => { - const fakePath = "/rendered/path/organizationGroup"; - const expectedParameters = { - organization: "organizationValue", - group: "groupValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationGroupPath', () => { - const result = client.organizationGroupPath("organizationValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationGroupName', () => { - const result = client.matchOrganizationFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromOrganizationGroupName', () => { - const result = client.matchGroupFromOrganizationGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.organizationGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationNotificationChannel', async () => { - const fakePath = "/rendered/path/organizationNotificationChannel"; - const expectedParameters = { - organization: "organizationValue", - notification_channel: "notificationChannelValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationNotificationChannelPath', () => { - const result = client.organizationNotificationChannelPath("organizationValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationNotificationChannelName', () => { - const result = client.matchOrganizationFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromOrganizationNotificationChannelName', () => { - const result = client.matchNotificationChannelFromOrganizationNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.organizationNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationService', async () => { - const fakePath = "/rendered/path/organizationService"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServicePath', () => { - const result = client.organizationServicePath("organizationValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceName', () => { - const result = client.matchOrganizationFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceName', () => { - const result = client.matchServiceFromOrganizationServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/organizationServiceServiceLevelObjective"; - const expectedParameters = { - organization: "organizationValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationServiceServiceLevelObjectivePath', () => { - const result = client.organizationServiceServiceLevelObjectivePath("organizationValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchOrganizationFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromOrganizationServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.organizationServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/organizationUptimeCheckConfig"; - const expectedParameters = { - organization: "organizationValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationUptimeCheckConfigPath', () => { - const result = client.organizationUptimeCheckConfigPath("organizationValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchOrganizationFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromOrganizationUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.organizationUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicy', async () => { - const fakePath = "/rendered/path/projectAlertPolicy"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyPath', () => { - const result = client.projectAlertPolicyPath("projectValue", "alertPolicyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyName', () => { - const result = client.matchProjectFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectAlertPolicyCondition', async () => { - const fakePath = "/rendered/path/projectAlertPolicyCondition"; - const expectedParameters = { - project: "projectValue", - alert_policy: "alertPolicyValue", - condition: "conditionValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectAlertPolicyConditionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectAlertPolicyConditionPath', () => { - const result = client.projectAlertPolicyConditionPath("projectValue", "alertPolicyValue", "conditionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectAlertPolicyConditionName', () => { - const result = client.matchProjectFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchAlertPolicyFromProjectAlertPolicyConditionName', () => { - const result = client.matchAlertPolicyFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "alertPolicyValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConditionFromProjectAlertPolicyConditionName', () => { - const result = client.matchConditionFromProjectAlertPolicyConditionName(fakePath); - assert.strictEqual(result, "conditionValue"); - assert((client.pathTemplates.projectAlertPolicyConditionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectChannelDescriptor', async () => { - const fakePath = "/rendered/path/projectChannelDescriptor"; - const expectedParameters = { - project: "projectValue", - channel_descriptor: "channelDescriptorValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectChannelDescriptorPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectChannelDescriptorPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectChannelDescriptorPath', () => { - const result = client.projectChannelDescriptorPath("projectValue", "channelDescriptorValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectChannelDescriptorName', () => { - const result = client.matchProjectFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchChannelDescriptorFromProjectChannelDescriptorName', () => { - const result = client.matchChannelDescriptorFromProjectChannelDescriptorName(fakePath); - assert.strictEqual(result, "channelDescriptorValue"); - assert((client.pathTemplates.projectChannelDescriptorPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectGroup', async () => { - const fakePath = "/rendered/path/projectGroup"; - const expectedParameters = { - project: "projectValue", - group: "groupValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectGroupPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectGroupPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectGroupPath', () => { - const result = client.projectGroupPath("projectValue", "groupValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectGroupPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectGroupName', () => { - const result = client.matchProjectFromProjectGroupName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGroupFromProjectGroupName', () => { - const result = client.matchGroupFromProjectGroupName(fakePath); - assert.strictEqual(result, "groupValue"); - assert((client.pathTemplates.projectGroupPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectNotificationChannel', async () => { - const fakePath = "/rendered/path/projectNotificationChannel"; - const expectedParameters = { - project: "projectValue", - notification_channel: "notificationChannelValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectNotificationChannelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectNotificationChannelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectNotificationChannelPath', () => { - const result = client.projectNotificationChannelPath("projectValue", "notificationChannelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectNotificationChannelName', () => { - const result = client.matchProjectFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchNotificationChannelFromProjectNotificationChannelName', () => { - const result = client.matchNotificationChannelFromProjectNotificationChannelName(fakePath); - assert.strictEqual(result, "notificationChannelValue"); - assert((client.pathTemplates.projectNotificationChannelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectService', async () => { - const fakePath = "/rendered/path/projectService"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServicePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServicePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServicePath', () => { - const result = client.projectServicePath("projectValue", "serviceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServicePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceName', () => { - const result = client.matchProjectFromProjectServiceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceName', () => { - const result = client.matchServiceFromProjectServiceName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServicePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectServiceServiceLevelObjective', async () => { - const fakePath = "/rendered/path/projectServiceServiceLevelObjective"; - const expectedParameters = { - project: "projectValue", - service: "serviceValue", - service_level_objective: "serviceLevelObjectiveValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectServiceServiceLevelObjectivePath', () => { - const result = client.projectServiceServiceLevelObjectivePath("projectValue", "serviceValue", "serviceLevelObjectiveValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchProjectFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName', () => { - const result = client.matchServiceLevelObjectiveFromProjectServiceServiceLevelObjectiveName(fakePath); - assert.strictEqual(result, "serviceLevelObjectiveValue"); - assert((client.pathTemplates.projectServiceServiceLevelObjectivePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectUptimeCheckConfig', async () => { - const fakePath = "/rendered/path/projectUptimeCheckConfig"; - const expectedParameters = { - project: "projectValue", - uptime_check_config: "uptimeCheckConfigValue", - }; - const client = new uptimecheckserviceModule.v3.UptimeCheckServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectUptimeCheckConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectUptimeCheckConfigPath', () => { - const result = client.projectUptimeCheckConfigPath("projectValue", "uptimeCheckConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectUptimeCheckConfigName', () => { - const result = client.matchProjectFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchUptimeCheckConfigFromProjectUptimeCheckConfigName', () => { - const result = client.matchUptimeCheckConfigFromProjectUptimeCheckConfigName(fakePath); - assert.strictEqual(result, "uptimeCheckConfigValue"); - assert((client.pathTemplates.projectUptimeCheckConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/monitoring/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/monitoring/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/monitoring/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/monitoring/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/naming-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/naming-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 674179f33ad4..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const naming = require('naming'); - -function main() { - const namingClient = new naming.NamingClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 08cea732e5e2..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as naming from 'naming'; - -function main() { - const namingClient = new naming.NamingClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index e40defab01d2..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {NamingClient} from 'naming'; - -// check that the client class type name can be used -function doStuffWithNamingClient(client: NamingClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const namingClient = new NamingClient(); - doStuffWithNamingClient(namingClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/test/gapic_naming_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/test/gapic_naming_v1beta1.ts.baseline deleted file mode 100644 index 559d526c38c8..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/esm/test/gapic_naming_v1beta1.ts.baseline +++ /dev/null @@ -1,1438 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as namingModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.NamingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new namingModule.v1beta1.NamingClient(); - const apiEndpoint = client.apiEndpoint1; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new namingModule.v1beta1.NamingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath1 is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = namingModule.v1beta1.NamingClient.servicePath1; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint1 is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = namingModule.v1beta1.NamingClient.apiEndpoint1; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new namingModule.v1beta1.NamingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = namingModule.v1beta1.NamingClient.port1; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new namingModule.v1beta1.NamingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new namingModule.v1beta1.NamingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.namingStub, undefined); - await client.initialize1(); - assert(client.namingStub); - }); - - it('has close method for the initialized client', done => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize1().catch(err => {throw err}); - assert(client.namingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.namingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId1(); - 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 namingModule.v1beta1.NamingClient({ - 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.getProjectId1((err?: Error|null, projectId?: string|null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - }); - - describe('paginatedMethodStream', () => { - it('invokes paginatedMethodStream without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.paginatedMethodStream = stubSimpleCall(expectedResponse); - const [response] = await client.paginatedMethodStream(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethodStream without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.paginatedMethodStream = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.paginatedMethodStream( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethodStream with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.paginatedMethodStream = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.paginatedMethodStream(request), expectedError); - }); - - it('invokes paginatedMethodStream with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.paginatedMethodStream(request), expectedError); - }); - }); - - describe('paginatedMethodAsync', () => { - it('invokes paginatedMethodAsync without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.paginatedMethodAsync = stubSimpleCall(expectedResponse); - const [response] = await client.paginatedMethodAsync(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethodAsync without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.paginatedMethodAsync = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.paginatedMethodAsync( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethodAsync with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.paginatedMethodAsync = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.paginatedMethodAsync(request), expectedError); - }); - - it('invokes paginatedMethodAsync with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.paginatedMethodAsync(request), expectedError); - }); - }); - - describe('checkLongRunningProgress', () => { - it('invokes checkLongRunningProgress without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.checkLongRunningProgress = stubSimpleCall(expectedResponse); - const [response] = await client.checkLongRunningProgress(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes checkLongRunningProgress without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.checkLongRunningProgress = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.checkLongRunningProgress( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes checkLongRunningProgress with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.checkLongRunningProgress = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkLongRunningProgress(request), expectedError); - }); - - it('invokes checkLongRunningProgress with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.checkLongRunningProgress(request), expectedError); - }); - }); - - describe('initialize', () => { - it('invokes initialize without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.initialize = stubSimpleCall(expectedResponse); - const [response] = await client.initialize(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes initialize without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.initialize = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.initialize( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes initialize with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.initialize = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.initialize(request), expectedError); - }); - - it('invokes initialize with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.initialize(request), expectedError); - }); - }); - - describe('servicePath', () => { - it('invokes servicePath without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.servicePath = stubSimpleCall(expectedResponse); - const [response] = await client.servicePath(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes servicePath without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.servicePath = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.servicePath( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes servicePath with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.servicePath = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.servicePath(request), expectedError); - }); - - it('invokes servicePath with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.servicePath(request), expectedError); - }); - }); - - describe('apiEndpoint', () => { - it('invokes apiEndpoint without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.apiEndpoint = stubSimpleCall(expectedResponse); - const [response] = await client.apiEndpoint(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes apiEndpoint without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.apiEndpoint = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.apiEndpoint( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes apiEndpoint with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.apiEndpoint = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.apiEndpoint(request), expectedError); - }); - - it('invokes apiEndpoint with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.apiEndpoint(request), expectedError); - }); - }); - - describe('port', () => { - it('invokes port without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.port = stubSimpleCall(expectedResponse); - const [response] = await client.port(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes port without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.port = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.port( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes port with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.port = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.port(request), expectedError); - }); - - it('invokes port with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.port(request), expectedError); - }); - }); - - describe('scopes', () => { - it('invokes scopes without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.scopes = stubSimpleCall(expectedResponse); - const [response] = await client.scopes(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes scopes without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.scopes = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.scopes( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes scopes with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.scopes = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.scopes(request), expectedError); - }); - - it('invokes scopes with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.scopes(request), expectedError); - }); - }); - - describe('getProjectId', () => { - it('invokes getProjectId without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.getProjectId = stubSimpleCall(expectedResponse); - const [response] = await client.getProjectId(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getProjectId without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.getProjectId = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getProjectId( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getProjectId with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.getProjectId = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getProjectId(request), expectedError); - }); - - it('invokes getProjectId with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getProjectId(request), expectedError); - }); - }); - - describe('getReservedWord', () => { - it('invokes getReservedWord without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.GetReservedWordRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.naming.v1beta1.ReservedWord() - ); - client.innerApiCalls.getReservedWord = stubSimpleCall(expectedResponse); - const [response] = await client.getReservedWord(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getReservedWord without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.GetReservedWordRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.naming.v1beta1.ReservedWord() - ); - client.innerApiCalls.getReservedWord = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getReservedWord( - request, - (err?: Error|null, result?: protos.google.naming.v1beta1.IReservedWord|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getReservedWord with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.GetReservedWordRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.getReservedWord = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getReservedWord(request), expectedError); - }); - - it('invokes getReservedWord with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.GetReservedWordRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getReservedWord(request), expectedError); - }); - }); - - describe('createABCDESomething', () => { - it('invokes createABCDESomething without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.createAbcdeSomething = stubSimpleCall(expectedResponse); - const [response] = await client.createABCDESomething(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createABCDESomething without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.createAbcdeSomething = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createABCDESomething( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createABCDESomething with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createAbcdeSomething = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createABCDESomething(request), expectedError); - }); - - it('invokes createABCDESomething with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createABCDESomething(request), expectedError); - }); - }); - - describe('longRunning', () => { - it('invokes longRunning without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.longRunning = stubLongRunningCall(expectedResponse); - const [operation] = await client.longRunning(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes longRunning without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.longRunning = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.longRunning( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes longRunning with call error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.longRunning = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.longRunning(request), expectedError); - }); - - it('invokes longRunning with LRO error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.longRunning = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.longRunning(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkLongRunningProgress1 without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkLongRunningProgress1(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkLongRunningProgress1 with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkLongRunningProgress1(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('paginatedMethod', () => { - it('invokes paginatedMethod without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - ]; - client.innerApiCalls.paginatedMethod = stubSimpleCall(expectedResponse); - const [response] = await client.paginatedMethod(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethod without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - ]; - client.innerApiCalls.paginatedMethod = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.paginatedMethod( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethod with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.paginatedMethod = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.paginatedMethod(request), expectedError); - }); - - it('invokes paginatedMethodStream1 without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - ]; - client.descriptors.page.paginatedMethod.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.paginatedMethodStream1(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.protobuf.Empty[] = []; - stream.on('data', (response: protos.google.protobuf.Empty) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.paginatedMethod.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.paginatedMethod, request)); - }); - - it('invokes paginatedMethodStream1 with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.paginatedMethod.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.paginatedMethodStream1(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.protobuf.Empty[] = []; - stream.on('data', (response: protos.google.protobuf.Empty) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.paginatedMethod.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.paginatedMethod, request)); - }); - - it('uses async iteration with paginatedMethod without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - ]; - client.descriptors.page.paginatedMethod.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.protobuf.IEmpty[] = []; - const iterable = client.paginatedMethodAsync1(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.paginatedMethod.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with paginatedMethod with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.paginatedMethod.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.paginatedMethodAsync1(request); - await assert.rejects(async () => { - const responses: protos.google.protobuf.IEmpty[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.paginatedMethod.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('projectExport', () => { - const fakePath = "/rendered/path/projectExport"; - const expectedParameters = { - project: "projectValue", - export: "exportValue", - }; - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize1().catch(err => {throw err}); - client.pathTemplates.projectExportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectExportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectExportPath', () => { - const result = client.projectExportPath("projectValue", "exportValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectExportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectExportName', () => { - const result = client.matchProjectFromProjectExportName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectExportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExportFromProjectExportName', () => { - const result = client.matchExportFromProjectExportName(fakePath); - assert.strictEqual(result, "exportValue"); - assert((client.pathTemplates.projectExportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectPackage', () => { - const fakePath = "/rendered/path/projectPackage"; - const expectedParameters = { - project: "projectValue", - package: "packageValue", - }; - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize1().catch(err => {throw err}); - client.pathTemplates.projectPackagePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPackagePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPackagePath', () => { - const result = client.projectPackagePath("projectValue", "packageValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPackagePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectPackageName', () => { - const result = client.matchProjectFromProjectPackageName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPackagePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchPackageFromProjectPackageName', () => { - const result = client.matchPackageFromProjectPackageName(fakePath); - assert.strictEqual(result, "packageValue"); - assert((client.pathTemplates.projectPackagePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/package.json b/core/generator/gapic-generator-typescript/baselines/naming-esm/package.json index cd6f9ad7dfb8..90f66efe8ad4 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/naming-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/naming-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/naming-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/naming-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/naming-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/naming/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/naming/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/naming/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/naming/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/naming/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/naming/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/naming/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/naming/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/naming/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/naming/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/naming/package.json b/core/generator/gapic-generator-typescript/baselines/naming/package.json index 6e82b91d416d..aea32bfdc6b4 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming/package.json +++ b/core/generator/gapic-generator-typescript/baselines/naming/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/naming/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/naming/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index cbfeb47d2170..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const naming = require('naming'); - -function main() { - const namingClient = new naming.NamingClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/naming/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/naming/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index c8cd80a20a9a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {NamingClient} from 'naming'; - -// check that the client class type name can be used -function doStuffWithNamingClient(client: NamingClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const namingClient = new NamingClient(); - doStuffWithNamingClient(namingClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/naming/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/naming/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/naming/test/gapic_naming_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/naming/test/gapic_naming_v1beta1.ts.baseline deleted file mode 100644 index 47d84bea6500..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/naming/test/gapic_naming_v1beta1.ts.baseline +++ /dev/null @@ -1,1429 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as namingModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.NamingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new namingModule.v1beta1.NamingClient(); - const apiEndpoint = client.apiEndpoint1; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new namingModule.v1beta1.NamingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath1 is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = namingModule.v1beta1.NamingClient.servicePath1; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint1 is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = namingModule.v1beta1.NamingClient.apiEndpoint1; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new namingModule.v1beta1.NamingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = namingModule.v1beta1.NamingClient.port1; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new namingModule.v1beta1.NamingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new namingModule.v1beta1.NamingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.namingStub, undefined); - await client.initialize1(); - assert(client.namingStub); - }); - - it('has close method for the initialized client', done => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize1().catch(err => {throw err}); - assert(client.namingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.namingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId1(); - 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 namingModule.v1beta1.NamingClient({ - 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.getProjectId1((err?: Error|null, projectId?: string|null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - }); - - describe('paginatedMethodStream', () => { - it('invokes paginatedMethodStream without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.paginatedMethodStream = stubSimpleCall(expectedResponse); - const [response] = await client.paginatedMethodStream(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethodStream without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.paginatedMethodStream = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.paginatedMethodStream( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethodStream with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.paginatedMethodStream = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.paginatedMethodStream(request), expectedError); - }); - - it('invokes paginatedMethodStream with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.paginatedMethodStream(request), expectedError); - }); - }); - - describe('paginatedMethodAsync', () => { - it('invokes paginatedMethodAsync without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.paginatedMethodAsync = stubSimpleCall(expectedResponse); - const [response] = await client.paginatedMethodAsync(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethodAsync without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.paginatedMethodAsync = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.paginatedMethodAsync( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethodAsync with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.paginatedMethodAsync = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.paginatedMethodAsync(request), expectedError); - }); - - it('invokes paginatedMethodAsync with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.paginatedMethodAsync(request), expectedError); - }); - }); - - describe('checkLongRunningProgress', () => { - it('invokes checkLongRunningProgress without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.checkLongRunningProgress = stubSimpleCall(expectedResponse); - const [response] = await client.checkLongRunningProgress(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes checkLongRunningProgress without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.checkLongRunningProgress = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.checkLongRunningProgress( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes checkLongRunningProgress with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.checkLongRunningProgress = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkLongRunningProgress(request), expectedError); - }); - - it('invokes checkLongRunningProgress with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.checkLongRunningProgress(request), expectedError); - }); - }); - - describe('initialize', () => { - it('invokes initialize without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.initialize = stubSimpleCall(expectedResponse); - const [response] = await client.initialize(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes initialize without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.initialize = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.initialize( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes initialize with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.initialize = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.initialize(request), expectedError); - }); - - it('invokes initialize with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.initialize(request), expectedError); - }); - }); - - describe('servicePath', () => { - it('invokes servicePath without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.servicePath = stubSimpleCall(expectedResponse); - const [response] = await client.servicePath(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes servicePath without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.servicePath = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.servicePath( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes servicePath with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.servicePath = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.servicePath(request), expectedError); - }); - - it('invokes servicePath with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.servicePath(request), expectedError); - }); - }); - - describe('apiEndpoint', () => { - it('invokes apiEndpoint without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.apiEndpoint = stubSimpleCall(expectedResponse); - const [response] = await client.apiEndpoint(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes apiEndpoint without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.apiEndpoint = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.apiEndpoint( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes apiEndpoint with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.apiEndpoint = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.apiEndpoint(request), expectedError); - }); - - it('invokes apiEndpoint with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.apiEndpoint(request), expectedError); - }); - }); - - describe('port', () => { - it('invokes port without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.port = stubSimpleCall(expectedResponse); - const [response] = await client.port(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes port without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.port = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.port( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes port with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.port = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.port(request), expectedError); - }); - - it('invokes port with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.port(request), expectedError); - }); - }); - - describe('scopes', () => { - it('invokes scopes without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.scopes = stubSimpleCall(expectedResponse); - const [response] = await client.scopes(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes scopes without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.scopes = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.scopes( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes scopes with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.scopes = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.scopes(request), expectedError); - }); - - it('invokes scopes with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.scopes(request), expectedError); - }); - }); - - describe('getProjectId', () => { - it('invokes getProjectId without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.getProjectId = stubSimpleCall(expectedResponse); - const [response] = await client.getProjectId(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getProjectId without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.getProjectId = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getProjectId( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getProjectId with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.getProjectId = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getProjectId(request), expectedError); - }); - - it('invokes getProjectId with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getProjectId(request), expectedError); - }); - }); - - describe('getReservedWord', () => { - it('invokes getReservedWord without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.GetReservedWordRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.naming.v1beta1.ReservedWord() - ); - client.innerApiCalls.getReservedWord = stubSimpleCall(expectedResponse); - const [response] = await client.getReservedWord(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getReservedWord without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.GetReservedWordRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.naming.v1beta1.ReservedWord() - ); - client.innerApiCalls.getReservedWord = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getReservedWord( - request, - (err?: Error|null, result?: protos.google.naming.v1beta1.IReservedWord|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getReservedWord with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.GetReservedWordRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.getReservedWord = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getReservedWord(request), expectedError); - }); - - it('invokes getReservedWord with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.GetReservedWordRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getReservedWord(request), expectedError); - }); - }); - - describe('createABCDESomething', () => { - it('invokes createABCDESomething without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.createAbcdeSomething = stubSimpleCall(expectedResponse); - const [response] = await client.createABCDESomething(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createABCDESomething without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.createAbcdeSomething = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createABCDESomething( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createABCDESomething with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createAbcdeSomething = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createABCDESomething(request), expectedError); - }); - - it('invokes createABCDESomething with closed client', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createABCDESomething(request), expectedError); - }); - }); - - describe('longRunning', () => { - it('invokes longRunning without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.longRunning = stubLongRunningCall(expectedResponse); - const [operation] = await client.longRunning(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes longRunning without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.longRunning = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.longRunning( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes longRunning with call error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.longRunning = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.longRunning(request), expectedError); - }); - - it('invokes longRunning with LRO error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.longRunning = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.longRunning(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkLongRunningProgress1 without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkLongRunningProgress1(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkLongRunningProgress1 with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkLongRunningProgress1(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('paginatedMethod', () => { - it('invokes paginatedMethod without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - ]; - client.innerApiCalls.paginatedMethod = stubSimpleCall(expectedResponse); - const [response] = await client.paginatedMethod(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethod without error using callback', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - ]; - client.innerApiCalls.paginatedMethod = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.paginatedMethod( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes paginatedMethod with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.paginatedMethod = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.paginatedMethod(request), expectedError); - }); - - it('invokes paginatedMethodStream1 without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - ]; - client.descriptors.page.paginatedMethod.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.paginatedMethodStream1(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.protobuf.Empty[] = []; - stream.on('data', (response: protos.google.protobuf.Empty) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.paginatedMethod.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.paginatedMethod, request)); - }); - - it('invokes paginatedMethodStream1 with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.paginatedMethod.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.paginatedMethodStream1(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.protobuf.Empty[] = []; - stream.on('data', (response: protos.google.protobuf.Empty) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.paginatedMethod.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.paginatedMethod, request)); - }); - - it('uses async iteration with paginatedMethod without error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - generateSampleMessage(new protos.google.protobuf.Empty()), - ]; - client.descriptors.page.paginatedMethod.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.protobuf.IEmpty[] = []; - const iterable = client.paginatedMethodAsync1(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.paginatedMethod.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with paginatedMethod with error', async () => { - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - const request = generateSampleMessage( - new protos.google.naming.v1beta1.PaginatedMethodRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.paginatedMethod.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.paginatedMethodAsync1(request); - await assert.rejects(async () => { - const responses: protos.google.protobuf.IEmpty[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.paginatedMethod.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('projectExport', async () => { - const fakePath = "/rendered/path/projectExport"; - const expectedParameters = { - project: "projectValue", - export: "exportValue", - }; - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - client.pathTemplates.projectExportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectExportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectExportPath', () => { - const result = client.projectExportPath("projectValue", "exportValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectExportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectExportName', () => { - const result = client.matchProjectFromProjectExportName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectExportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExportFromProjectExportName', () => { - const result = client.matchExportFromProjectExportName(fakePath); - assert.strictEqual(result, "exportValue"); - assert((client.pathTemplates.projectExportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectPackage', async () => { - const fakePath = "/rendered/path/projectPackage"; - const expectedParameters = { - project: "projectValue", - package: "packageValue", - }; - const client = new namingModule.v1beta1.NamingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize1(); - client.pathTemplates.projectPackagePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPackagePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPackagePath', () => { - const result = client.projectPackagePath("projectValue", "packageValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPackagePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectPackageName', () => { - const result = client.matchProjectFromProjectPackageName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPackagePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchPackageFromProjectPackageName', () => { - const result = client.matchPackageFromProjectPackageName(fakePath); - assert.strictEqual(result, "packageValue"); - assert((client.pathTemplates.projectPackagePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/naming/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/naming/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/naming/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/naming/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/redis-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/redis-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 9a20333d1050..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const redis = require('redis'); - -function main() { - const cloudRedisClient = new redis.CloudRedisClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index e5e4bbbc3502..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as redis from 'redis'; - -function main() { - const cloudRedisClient = new redis.CloudRedisClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index d585e083599a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {CloudRedisClient} from 'redis'; - -// check that the client class type name can be used -function doStuffWithCloudRedisClient(client: CloudRedisClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const cloudRedisClient = new CloudRedisClient(); - doStuffWithCloudRedisClient(cloudRedisClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/test/gapic_cloud_redis_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/test/gapic_cloud_redis_v1beta1.ts.baseline deleted file mode 100644 index b3f5f20a0fa3..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/esm/test/gapic_cloud_redis_v1beta1.ts.baseline +++ /dev/null @@ -1,1909 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as cloudredisModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.CloudRedisClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'redis.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = cloudredisModule.v1beta1.CloudRedisClient.servicePath; - assert.strictEqual(servicePath, 'redis.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = cloudredisModule.v1beta1.CloudRedisClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'redis.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'redis.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'redis.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new cloudredisModule.v1beta1.CloudRedisClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'redis.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new cloudredisModule.v1beta1.CloudRedisClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'redis.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new cloudredisModule.v1beta1.CloudRedisClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = cloudredisModule.v1beta1.CloudRedisClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudRedisStub, undefined); - await client.initialize(); - assert(client.cloudRedisStub); - }); - - it('has close method for the initialized client', done => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.cloudRedisStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudRedisStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - 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); - }); - }); - - describe('getInstance', () => { - it('invokes getInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.GetInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.GetInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.Instance() - ); - client.innerApiCalls.getInstance = stubSimpleCall(expectedResponse); - const [response] = await client.getInstance(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.GetInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.GetInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.Instance() - ); - client.innerApiCalls.getInstance = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getInstance( - request, - (err?: Error|null, result?: protos.google.cloud.redis.v1beta1.IInstance|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInstance with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.GetInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.GetInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getInstance = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInstance with closed client', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.GetInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.GetInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getInstance(request), expectedError); - }); - }); - - describe('createInstance', () => { - it('invokes createInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.CreateInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.CreateInstanceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.createInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.CreateInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.CreateInstanceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.CreateInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.CreateInstanceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.createInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.CreateInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.CreateInstanceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.createInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCreateInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('updateInstance', () => { - it('invokes updateInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.UpdateInstanceRequest() - ); - request.instance ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.UpdateInstanceRequest', ['instance', 'name']); - request.instance.name = defaultValue1; - const expectedHeaderRequestParams = `instance.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.updateInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.updateInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.UpdateInstanceRequest() - ); - request.instance ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.UpdateInstanceRequest', ['instance', 'name']); - request.instance.name = defaultValue1; - const expectedHeaderRequestParams = `instance.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.updateInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.UpdateInstanceRequest() - ); - request.instance ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.UpdateInstanceRequest', ['instance', 'name']); - request.instance.name = defaultValue1; - const expectedHeaderRequestParams = `instance.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.updateInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.UpdateInstanceRequest() - ); - request.instance ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.UpdateInstanceRequest', ['instance', 'name']); - request.instance.name = defaultValue1; - const expectedHeaderRequestParams = `instance.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.updateInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkUpdateInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkUpdateInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkUpdateInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkUpdateInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('importInstance', () => { - it('invokes importInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ImportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ImportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.importInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ImportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ImportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ImportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ImportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.importInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ImportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ImportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.importInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkImportInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('exportInstance', () => { - it('invokes exportInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ExportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ExportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ExportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ExportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ExportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ExportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ExportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ExportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('failoverInstance', () => { - it('invokes failoverInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.FailoverInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.FailoverInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.failoverInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.failoverInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failoverInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.FailoverInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.FailoverInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.failoverInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.failoverInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failoverInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.FailoverInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.FailoverInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.failoverInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.failoverInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failoverInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.FailoverInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.FailoverInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.failoverInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.failoverInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkFailoverInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkFailoverInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkFailoverInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkFailoverInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('deleteInstance', () => { - it('invokes deleteInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.DeleteInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.DeleteInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.deleteInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.deleteInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.DeleteInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.DeleteInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.deleteInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.DeleteInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.DeleteInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.deleteInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.DeleteInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.DeleteInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.deleteInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkDeleteInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkDeleteInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkDeleteInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkDeleteInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listInstances', () => { - it('invokes listInstances without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - ]; - client.innerApiCalls.listInstances = stubSimpleCall(expectedResponse); - const [response] = await client.listInstances(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInstances without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - ]; - client.innerApiCalls.listInstances = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listInstances( - request, - (err?: Error|null, result?: protos.google.cloud.redis.v1beta1.IInstance[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInstances with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listInstances = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listInstances(request), expectedError); - const actualRequest = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInstancesStream without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - ]; - client.descriptors.page.listInstances.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listInstancesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.redis.v1beta1.Instance[] = []; - stream.on('data', (response: protos.google.cloud.redis.v1beta1.Instance) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listInstances.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listInstances, request)); - assert( - (client.descriptors.page.listInstances.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listInstancesStream with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listInstances.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listInstancesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.redis.v1beta1.Instance[] = []; - stream.on('data', (response: protos.google.cloud.redis.v1beta1.Instance) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listInstances.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listInstances, request)); - assert( - (client.descriptors.page.listInstances.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listInstances without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - ]; - client.descriptors.page.listInstances.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.redis.v1beta1.IInstance[] = []; - const iterable = client.listInstancesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listInstances.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listInstances.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listInstances with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listInstances.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listInstancesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.redis.v1beta1.IInstance[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listInstances.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listInstances.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - describe('getOperation', () => { - it('invokes getOperation without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const response = await client.getOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0).calledWith(request) - ); - }); - it('invokes getOperation without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - client.operationsClient.getOperation = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient.getOperation( - request, - undefined, - ( - err?: Error | null, - result?: operationsProtos.google.longrunning.Operation | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - it('invokes getOperation with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest() - ); - const expectedError = new Error('expected'); - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(async () => {await client.getOperation(request)}, expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0).calledWith(request)); - }); - }); - describe('cancelOperation', () => { - it('invokes cancelOperation without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.operationsClient.cancelOperation = stubSimpleCall(expectedResponse); - const response = await client.cancelOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.operationsClient.cancelOperation as SinonStub) - .getCall(0).calledWith(request) - ); - }); - it('invokes cancelOperation without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.operationsClient.cancelOperation = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient.cancelOperation( - request, - undefined, - ( - err?: Error | null, - result?: protos.google.protobuf.Empty | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.cancelOperation as SinonStub) - .getCall(0)); - }); - it('invokes cancelOperation with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest() - ); - const expectedError = new Error('expected'); - client.operationsClient.cancelOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(async () => {await client.cancelOperation(request)}, expectedError); - assert((client.operationsClient.cancelOperation as SinonStub) - .getCall(0).calledWith(request)); - }); - }); - describe('deleteOperation', () => { - it('invokes deleteOperation without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.operationsClient.deleteOperation = stubSimpleCall(expectedResponse); - const response = await client.deleteOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.operationsClient.deleteOperation as SinonStub) - .getCall(0).calledWith(request) - ); - }); - it('invokes deleteOperation without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.operationsClient.deleteOperation = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient.deleteOperation( - request, - undefined, - ( - err?: Error | null, - result?: protos.google.protobuf.Empty | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.deleteOperation as SinonStub) - .getCall(0)); - }); - it('invokes deleteOperation with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest() - ); - const expectedError = new Error('expected'); - client.operationsClient.deleteOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(async () => {await client.deleteOperation(request)}, expectedError); - assert((client.operationsClient.deleteOperation as SinonStub) - .getCall(0).calledWith(request)); - }); - }); - describe('listOperationsAsync', () => { - it('uses async iteration with listOperations without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsRequest() - ); - const expectedResponse = [ - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse() - ), - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse() - ), - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse() - ), - ]; - client.operationsClient.descriptor.listOperations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: operationsProtos.google.longrunning.IOperation[] = []; - const iterable = client.operationsClient.listOperationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.operationsClient.descriptor.listOperations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - it('uses async iteration with listOperations with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsRequest() - ); - const expectedError = new Error('expected'); - client.operationsClient.descriptor.listOperations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.operationsClient.listOperationsAsync(request); - await assert.rejects(async () => { - const responses: operationsProtos.google.longrunning.IOperation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.operationsClient.descriptor.listOperations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('instance', () => { - const fakePath = "/rendered/path/instance"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - instance: "instanceValue", - }; - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.instancePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.instancePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('instancePath', () => { - const result = client.instancePath("projectValue", "locationValue", "instanceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.instancePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromInstanceName', () => { - const result = client.matchProjectFromInstanceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.instancePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromInstanceName', () => { - const result = client.matchLocationFromInstanceName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.instancePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchInstanceFromInstanceName', () => { - const result = client.matchInstanceFromInstanceName(fakePath); - assert.strictEqual(result, "instanceValue"); - assert((client.pathTemplates.instancePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('location', () => { - const fakePath = "/rendered/path/location"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - }; - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.locationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.locationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath("projectValue", "locationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/package.json b/core/generator/gapic-generator-typescript/baselines/redis-esm/package.json index 7d0e5005ce24..383e30d02453 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/redis-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/redis-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/redis-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/redis-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/redis-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/redis/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/redis/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/redis/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/redis/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/redis/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/redis/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/redis/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/redis/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/redis/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/redis/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/redis/package.json b/core/generator/gapic-generator-typescript/baselines/redis/package.json index 0997ee995e3c..3e4e7fda3b87 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis/package.json +++ b/core/generator/gapic-generator-typescript/baselines/redis/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/redis/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/redis/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index d247d541c8a7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const redis = require('redis'); - -function main() { - const cloudRedisClient = new redis.CloudRedisClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/redis/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/redis/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 5ca80129b7e0..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {CloudRedisClient} from 'redis'; - -// check that the client class type name can be used -function doStuffWithCloudRedisClient(client: CloudRedisClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const cloudRedisClient = new CloudRedisClient(); - doStuffWithCloudRedisClient(cloudRedisClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/redis/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/redis/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/redis/test/gapic_cloud_redis_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/redis/test/gapic_cloud_redis_v1beta1.ts.baseline deleted file mode 100644 index 37c85361962e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/redis/test/gapic_cloud_redis_v1beta1.ts.baseline +++ /dev/null @@ -1,1900 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as cloudredisModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.CloudRedisClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'redis.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = cloudredisModule.v1beta1.CloudRedisClient.servicePath; - assert.strictEqual(servicePath, 'redis.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = cloudredisModule.v1beta1.CloudRedisClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'redis.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'redis.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'redis.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new cloudredisModule.v1beta1.CloudRedisClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'redis.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new cloudredisModule.v1beta1.CloudRedisClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'redis.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new cloudredisModule.v1beta1.CloudRedisClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = cloudredisModule.v1beta1.CloudRedisClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudRedisStub, undefined); - await client.initialize(); - assert(client.cloudRedisStub); - }); - - it('has close method for the initialized client', done => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.cloudRedisStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudRedisStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - 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); - }); - }); - - describe('getInstance', () => { - it('invokes getInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.GetInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.GetInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.Instance() - ); - client.innerApiCalls.getInstance = stubSimpleCall(expectedResponse); - const [response] = await client.getInstance(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.GetInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.GetInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.Instance() - ); - client.innerApiCalls.getInstance = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getInstance( - request, - (err?: Error|null, result?: protos.google.cloud.redis.v1beta1.IInstance|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInstance with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.GetInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.GetInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getInstance = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getInstance with closed client', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.GetInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.GetInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getInstance(request), expectedError); - }); - }); - - describe('createInstance', () => { - it('invokes createInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.CreateInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.CreateInstanceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.createInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.CreateInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.CreateInstanceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.CreateInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.CreateInstanceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.createInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.CreateInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.CreateInstanceRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.createInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCreateInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('updateInstance', () => { - it('invokes updateInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.UpdateInstanceRequest() - ); - request.instance ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.UpdateInstanceRequest', ['instance', 'name']); - request.instance.name = defaultValue1; - const expectedHeaderRequestParams = `instance.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.updateInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.updateInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.UpdateInstanceRequest() - ); - request.instance ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.UpdateInstanceRequest', ['instance', 'name']); - request.instance.name = defaultValue1; - const expectedHeaderRequestParams = `instance.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.updateInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.UpdateInstanceRequest() - ); - request.instance ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.UpdateInstanceRequest', ['instance', 'name']); - request.instance.name = defaultValue1; - const expectedHeaderRequestParams = `instance.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.updateInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.UpdateInstanceRequest() - ); - request.instance ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.UpdateInstanceRequest', ['instance', 'name']); - request.instance.name = defaultValue1; - const expectedHeaderRequestParams = `instance.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.updateInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkUpdateInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkUpdateInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkUpdateInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkUpdateInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('importInstance', () => { - it('invokes importInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ImportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ImportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.importInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ImportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ImportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ImportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ImportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.importInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ImportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ImportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.importInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkImportInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('exportInstance', () => { - it('invokes exportInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ExportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ExportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ExportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ExportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ExportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ExportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ExportInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ExportInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('failoverInstance', () => { - it('invokes failoverInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.FailoverInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.FailoverInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.failoverInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.failoverInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failoverInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.FailoverInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.FailoverInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.failoverInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.failoverInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failoverInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.FailoverInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.FailoverInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.failoverInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.failoverInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes failoverInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.FailoverInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.FailoverInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.failoverInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.failoverInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.failoverInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkFailoverInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkFailoverInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkFailoverInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkFailoverInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('deleteInstance', () => { - it('invokes deleteInstance without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.DeleteInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.DeleteInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.deleteInstance = stubLongRunningCall(expectedResponse); - const [operation] = await client.deleteInstance(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInstance without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.DeleteInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.DeleteInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.deleteInstance = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteInstance( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInstance with call error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.DeleteInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.DeleteInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteInstance = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.deleteInstance(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteInstance with LRO error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.DeleteInstanceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.DeleteInstanceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteInstance = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.deleteInstance(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteInstance as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkDeleteInstanceProgress without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkDeleteInstanceProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkDeleteInstanceProgress with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkDeleteInstanceProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listInstances', () => { - it('invokes listInstances without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - ]; - client.innerApiCalls.listInstances = stubSimpleCall(expectedResponse); - const [response] = await client.listInstances(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInstances without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - ]; - client.innerApiCalls.listInstances = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listInstances( - request, - (err?: Error|null, result?: protos.google.cloud.redis.v1beta1.IInstance[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInstances with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listInstances = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listInstances(request), expectedError); - const actualRequest = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listInstances as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listInstancesStream without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - ]; - client.descriptors.page.listInstances.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listInstancesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.redis.v1beta1.Instance[] = []; - stream.on('data', (response: protos.google.cloud.redis.v1beta1.Instance) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listInstances.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listInstances, request)); - assert( - (client.descriptors.page.listInstances.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listInstancesStream with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listInstances.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listInstancesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.redis.v1beta1.Instance[] = []; - stream.on('data', (response: protos.google.cloud.redis.v1beta1.Instance) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listInstances.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listInstances, request)); - assert( - (client.descriptors.page.listInstances.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listInstances without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - generateSampleMessage(new protos.google.cloud.redis.v1beta1.Instance()), - ]; - client.descriptors.page.listInstances.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.redis.v1beta1.IInstance[] = []; - const iterable = client.listInstancesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listInstances.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listInstances.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listInstances with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.redis.v1beta1.ListInstancesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.redis.v1beta1.ListInstancesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listInstances.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listInstancesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.redis.v1beta1.IInstance[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listInstances.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listInstances.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - describe('getOperation', () => { - it('invokes getOperation without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const response = await client.getOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0).calledWith(request) - ); - }); - it('invokes getOperation without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - client.operationsClient.getOperation = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient.getOperation( - request, - undefined, - ( - err?: Error | null, - result?: operationsProtos.google.longrunning.Operation | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - it('invokes getOperation with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.GetOperationRequest() - ); - const expectedError = new Error('expected'); - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(async () => {await client.getOperation(request)}, expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0).calledWith(request)); - }); - }); - describe('cancelOperation', () => { - it('invokes cancelOperation without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.operationsClient.cancelOperation = stubSimpleCall(expectedResponse); - const response = await client.cancelOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.operationsClient.cancelOperation as SinonStub) - .getCall(0).calledWith(request) - ); - }); - it('invokes cancelOperation without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.operationsClient.cancelOperation = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient.cancelOperation( - request, - undefined, - ( - err?: Error | null, - result?: protos.google.protobuf.Empty | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.cancelOperation as SinonStub) - .getCall(0)); - }); - it('invokes cancelOperation with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.CancelOperationRequest() - ); - const expectedError = new Error('expected'); - client.operationsClient.cancelOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(async () => {await client.cancelOperation(request)}, expectedError); - assert((client.operationsClient.cancelOperation as SinonStub) - .getCall(0).calledWith(request)); - }); - }); - describe('deleteOperation', () => { - it('invokes deleteOperation without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.operationsClient.deleteOperation = stubSimpleCall(expectedResponse); - const response = await client.deleteOperation(request); - assert.deepStrictEqual(response, [expectedResponse]); - assert((client.operationsClient.deleteOperation as SinonStub) - .getCall(0).calledWith(request) - ); - }); - it('invokes deleteOperation without error using callback', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.operationsClient.deleteOperation = sinon.stub().callsArgWith(2, null, expectedResponse); - const promise = new Promise((resolve, reject) => { - client.operationsClient.deleteOperation( - request, - undefined, - ( - err?: Error | null, - result?: protos.google.protobuf.Empty | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }).catch(err => {throw err}); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.operationsClient.deleteOperation as SinonStub) - .getCall(0)); - }); - it('invokes deleteOperation with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.DeleteOperationRequest() - ); - const expectedError = new Error('expected'); - client.operationsClient.deleteOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(async () => {await client.deleteOperation(request)}, expectedError); - assert((client.operationsClient.deleteOperation as SinonStub) - .getCall(0).calledWith(request)); - }); - }); - describe('listOperationsAsync', () => { - it('uses async iteration with listOperations without error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsRequest() - ); - const expectedResponse = [ - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse() - ), - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse() - ), - generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsResponse() - ), - ]; - client.operationsClient.descriptor.listOperations.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: operationsProtos.google.longrunning.IOperation[] = []; - const iterable = client.operationsClient.listOperationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.operationsClient.descriptor.listOperations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - it('uses async iteration with listOperations with error', async () => { - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new operationsProtos.google.longrunning.ListOperationsRequest() - ); - const expectedError = new Error('expected'); - client.operationsClient.descriptor.listOperations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.operationsClient.listOperationsAsync(request); - await assert.rejects(async () => { - const responses: operationsProtos.google.longrunning.IOperation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.operationsClient.descriptor.listOperations.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('instance', async () => { - const fakePath = "/rendered/path/instance"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - instance: "instanceValue", - }; - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.instancePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.instancePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('instancePath', () => { - const result = client.instancePath("projectValue", "locationValue", "instanceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.instancePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromInstanceName', () => { - const result = client.matchProjectFromInstanceName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.instancePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromInstanceName', () => { - const result = client.matchLocationFromInstanceName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.instancePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchInstanceFromInstanceName', () => { - const result = client.matchInstanceFromInstanceName(fakePath); - assert.strictEqual(result, "instanceValue"); - assert((client.pathTemplates.instancePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('location', async () => { - const fakePath = "/rendered/path/location"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - }; - const client = new cloudredisModule.v1beta1.CloudRedisClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.locationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.locationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath("projectValue", "locationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/redis/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/redis/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/redis/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/redis/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/retail-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/retail-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 7b9b41bbb335..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const retail = require('retail'); - -function main() { - const analyticsServiceClient = new retail.AnalyticsServiceClient(); - const branchServiceClient = new retail.BranchServiceClient(); - const catalogServiceClient = new retail.CatalogServiceClient(); - const completionServiceClient = new retail.CompletionServiceClient(); - const controlServiceClient = new retail.ControlServiceClient(); - const conversationalSearchServiceClient = new retail.ConversationalSearchServiceClient(); - const generativeQuestionServiceClient = new retail.GenerativeQuestionServiceClient(); - const merchantCenterAccountLinkServiceClient = new retail.MerchantCenterAccountLinkServiceClient(); - const modelServiceClient = new retail.ModelServiceClient(); - const predictionServiceClient = new retail.PredictionServiceClient(); - const productServiceClient = new retail.ProductServiceClient(); - const projectServiceClient = new retail.ProjectServiceClient(); - const searchServiceClient = new retail.SearchServiceClient(); - const servingConfigServiceClient = new retail.ServingConfigServiceClient(); - const userEventServiceClient = new retail.UserEventServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index be1f058a2723..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as retail from 'retail'; - -function main() { - const analyticsServiceClient = new retail.AnalyticsServiceClient(); - const branchServiceClient = new retail.BranchServiceClient(); - const catalogServiceClient = new retail.CatalogServiceClient(); - const completionServiceClient = new retail.CompletionServiceClient(); - const controlServiceClient = new retail.ControlServiceClient(); - const conversationalSearchServiceClient = new retail.ConversationalSearchServiceClient(); - const generativeQuestionServiceClient = new retail.GenerativeQuestionServiceClient(); - const merchantCenterAccountLinkServiceClient = new retail.MerchantCenterAccountLinkServiceClient(); - const modelServiceClient = new retail.ModelServiceClient(); - const predictionServiceClient = new retail.PredictionServiceClient(); - const productServiceClient = new retail.ProductServiceClient(); - const projectServiceClient = new retail.ProjectServiceClient(); - const searchServiceClient = new retail.SearchServiceClient(); - const servingConfigServiceClient = new retail.ServingConfigServiceClient(); - const userEventServiceClient = new retail.UserEventServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index bdba7b07a3bf..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,117 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {AnalyticsServiceClient, BranchServiceClient, CatalogServiceClient, CompletionServiceClient, ControlServiceClient, ConversationalSearchServiceClient, GenerativeQuestionServiceClient, MerchantCenterAccountLinkServiceClient, ModelServiceClient, PredictionServiceClient, ProductServiceClient, ProjectServiceClient, SearchServiceClient, ServingConfigServiceClient, UserEventServiceClient} from 'retail'; - -// check that the client class type name can be used -function doStuffWithAnalyticsServiceClient(client: AnalyticsServiceClient) { - client.close(); -} -function doStuffWithBranchServiceClient(client: BranchServiceClient) { - client.close(); -} -function doStuffWithCatalogServiceClient(client: CatalogServiceClient) { - client.close(); -} -function doStuffWithCompletionServiceClient(client: CompletionServiceClient) { - client.close(); -} -function doStuffWithControlServiceClient(client: ControlServiceClient) { - client.close(); -} -function doStuffWithConversationalSearchServiceClient(client: ConversationalSearchServiceClient) { - client.close(); -} -function doStuffWithGenerativeQuestionServiceClient(client: GenerativeQuestionServiceClient) { - client.close(); -} -function doStuffWithMerchantCenterAccountLinkServiceClient(client: MerchantCenterAccountLinkServiceClient) { - client.close(); -} -function doStuffWithModelServiceClient(client: ModelServiceClient) { - client.close(); -} -function doStuffWithPredictionServiceClient(client: PredictionServiceClient) { - client.close(); -} -function doStuffWithProductServiceClient(client: ProductServiceClient) { - client.close(); -} -function doStuffWithProjectServiceClient(client: ProjectServiceClient) { - client.close(); -} -function doStuffWithSearchServiceClient(client: SearchServiceClient) { - client.close(); -} -function doStuffWithServingConfigServiceClient(client: ServingConfigServiceClient) { - client.close(); -} -function doStuffWithUserEventServiceClient(client: UserEventServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const analyticsServiceClient = new AnalyticsServiceClient(); - doStuffWithAnalyticsServiceClient(analyticsServiceClient); - // check that the client instance can be created - const branchServiceClient = new BranchServiceClient(); - doStuffWithBranchServiceClient(branchServiceClient); - // check that the client instance can be created - const catalogServiceClient = new CatalogServiceClient(); - doStuffWithCatalogServiceClient(catalogServiceClient); - // check that the client instance can be created - const completionServiceClient = new CompletionServiceClient(); - doStuffWithCompletionServiceClient(completionServiceClient); - // check that the client instance can be created - const controlServiceClient = new ControlServiceClient(); - doStuffWithControlServiceClient(controlServiceClient); - // check that the client instance can be created - const conversationalSearchServiceClient = new ConversationalSearchServiceClient(); - doStuffWithConversationalSearchServiceClient(conversationalSearchServiceClient); - // check that the client instance can be created - const generativeQuestionServiceClient = new GenerativeQuestionServiceClient(); - doStuffWithGenerativeQuestionServiceClient(generativeQuestionServiceClient); - // check that the client instance can be created - const merchantCenterAccountLinkServiceClient = new MerchantCenterAccountLinkServiceClient(); - doStuffWithMerchantCenterAccountLinkServiceClient(merchantCenterAccountLinkServiceClient); - // check that the client instance can be created - const modelServiceClient = new ModelServiceClient(); - doStuffWithModelServiceClient(modelServiceClient); - // check that the client instance can be created - const predictionServiceClient = new PredictionServiceClient(); - doStuffWithPredictionServiceClient(predictionServiceClient); - // check that the client instance can be created - const productServiceClient = new ProductServiceClient(); - doStuffWithProductServiceClient(productServiceClient); - // check that the client instance can be created - const projectServiceClient = new ProjectServiceClient(); - doStuffWithProjectServiceClient(projectServiceClient); - // check that the client instance can be created - const searchServiceClient = new SearchServiceClient(); - doStuffWithSearchServiceClient(searchServiceClient); - // check that the client instance can be created - const servingConfigServiceClient = new ServingConfigServiceClient(); - doStuffWithServingConfigServiceClient(servingConfigServiceClient); - // check that the client instance can be created - const userEventServiceClient = new UserEventServiceClient(); - doStuffWithUserEventServiceClient(userEventServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_analytics_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_analytics_service_v2alpha.ts.baseline deleted file mode 100644 index 8a505ca00160..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_analytics_service_v2alpha.ts.baseline +++ /dev/null @@ -1,952 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as analyticsserviceModule from '../src/index.js'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.AnalyticsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = analyticsserviceModule.v2alpha.AnalyticsServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = analyticsserviceModule.v2alpha.AnalyticsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new analyticsserviceModule.v2alpha.AnalyticsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = analyticsserviceModule.v2alpha.AnalyticsServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.analyticsServiceStub, undefined); - await client.initialize(); - assert(client.analyticsServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.analyticsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.analyticsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - 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); - }); - }); - - describe('exportAnalyticsMetrics', () => { - it('invokes exportAnalyticsMetrics without error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportAnalyticsMetrics = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportAnalyticsMetrics(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAnalyticsMetrics without error using callback', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportAnalyticsMetrics = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportAnalyticsMetrics( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAnalyticsMetrics with call error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportAnalyticsMetrics = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportAnalyticsMetrics(request), expectedError); - const actualRequest = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAnalyticsMetrics with LRO error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportAnalyticsMetrics = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportAnalyticsMetrics(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportAnalyticsMetricsProgress without error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportAnalyticsMetricsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportAnalyticsMetricsProgress with error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportAnalyticsMetricsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_branch_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_branch_service_v2alpha.ts.baseline deleted file mode 100644 index 1e29cd127728..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_branch_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1002 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as branchserviceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v2alpha.BranchServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = branchserviceModule.v2alpha.BranchServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = branchserviceModule.v2alpha.BranchServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new branchserviceModule.v2alpha.BranchServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new branchserviceModule.v2alpha.BranchServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new branchserviceModule.v2alpha.BranchServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = branchserviceModule.v2alpha.BranchServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.branchServiceStub, undefined); - await client.initialize(); - assert(client.branchServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.branchServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.branchServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - 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); - }); - }); - - describe('listBranches', () => { - it('invokes listBranches without error', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListBranchesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesResponse() - ); - client.innerApiCalls.listBranches = stubSimpleCall(expectedResponse); - const [response] = await client.listBranches(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBranches without error using callback', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListBranchesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesResponse() - ); - client.innerApiCalls.listBranches = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBranches( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IListBranchesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBranches with error', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListBranchesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBranches = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBranches(request), expectedError); - const actualRequest = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBranches with closed client', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListBranchesRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listBranches(request), expectedError); - }); - }); - - describe('getBranch', () => { - it('invokes getBranch without error', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetBranchRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Branch() - ); - client.innerApiCalls.getBranch = stubSimpleCall(expectedResponse); - const [response] = await client.getBranch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBranch without error using callback', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetBranchRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Branch() - ); - client.innerApiCalls.getBranch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBranch( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IBranch|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBranch with error', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetBranchRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBranch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBranch(request), expectedError); - const actualRequest = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBranch with closed client', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetBranchRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBranch(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_catalog_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_catalog_service_v2alpha.ts.baseline deleted file mode 100644 index 38dc32adbca3..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_catalog_service_v2alpha.ts.baseline +++ /dev/null @@ -1,2316 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as catalogserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.CatalogServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = catalogserviceModule.v2alpha.CatalogServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = catalogserviceModule.v2alpha.CatalogServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new catalogserviceModule.v2alpha.CatalogServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = catalogserviceModule.v2alpha.CatalogServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.catalogServiceStub, undefined); - await client.initialize(); - assert(client.catalogServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.catalogServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.catalogServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - 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); - }); - }); - - describe('updateCatalog', () => { - it('invokes updateCatalog without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCatalogRequest() - ); - request.catalog ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCatalogRequest', ['catalog', 'name']); - request.catalog.name = defaultValue1; - const expectedHeaderRequestParams = `catalog.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Catalog() - ); - client.innerApiCalls.updateCatalog = stubSimpleCall(expectedResponse); - const [response] = await client.updateCatalog(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCatalog without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCatalogRequest() - ); - request.catalog ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCatalogRequest', ['catalog', 'name']); - request.catalog.name = defaultValue1; - const expectedHeaderRequestParams = `catalog.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Catalog() - ); - client.innerApiCalls.updateCatalog = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCatalog( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICatalog|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCatalog with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCatalogRequest() - ); - request.catalog ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCatalogRequest', ['catalog', 'name']); - request.catalog.name = defaultValue1; - const expectedHeaderRequestParams = `catalog.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCatalog = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCatalog(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCatalog with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCatalogRequest() - ); - request.catalog ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCatalogRequest', ['catalog', 'name']); - request.catalog.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCatalog(request), expectedError); - }); - }); - - describe('setDefaultBranch', () => { - it('invokes setDefaultBranch without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.setDefaultBranch = stubSimpleCall(expectedResponse); - const [response] = await client.setDefaultBranch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setDefaultBranch without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.setDefaultBranch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setDefaultBranch( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setDefaultBranch with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.setDefaultBranch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setDefaultBranch(request), expectedError); - const actualRequest = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setDefaultBranch with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.setDefaultBranch(request), expectedError); - }); - }); - - describe('getDefaultBranch', () => { - it('invokes getDefaultBranch without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchResponse() - ); - client.innerApiCalls.getDefaultBranch = stubSimpleCall(expectedResponse); - const [response] = await client.getDefaultBranch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDefaultBranch without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchResponse() - ); - client.innerApiCalls.getDefaultBranch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDefaultBranch( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IGetDefaultBranchResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDefaultBranch with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDefaultBranch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDefaultBranch(request), expectedError); - const actualRequest = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDefaultBranch with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDefaultBranch(request), expectedError); - }); - }); - - describe('getCompletionConfig', () => { - it('invokes getCompletionConfig without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetCompletionConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetCompletionConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompletionConfig() - ); - client.innerApiCalls.getCompletionConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getCompletionConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCompletionConfig without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetCompletionConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetCompletionConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompletionConfig() - ); - client.innerApiCalls.getCompletionConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getCompletionConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICompletionConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCompletionConfig with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetCompletionConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetCompletionConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getCompletionConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getCompletionConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCompletionConfig with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetCompletionConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetCompletionConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getCompletionConfig(request), expectedError); - }); - }); - - describe('updateCompletionConfig', () => { - it('invokes updateCompletionConfig without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest() - ); - request.completionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest', ['completionConfig', 'name']); - request.completionConfig.name = defaultValue1; - const expectedHeaderRequestParams = `completion_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompletionConfig() - ); - client.innerApiCalls.updateCompletionConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateCompletionConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCompletionConfig without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest() - ); - request.completionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest', ['completionConfig', 'name']); - request.completionConfig.name = defaultValue1; - const expectedHeaderRequestParams = `completion_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompletionConfig() - ); - client.innerApiCalls.updateCompletionConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCompletionConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICompletionConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCompletionConfig with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest() - ); - request.completionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest', ['completionConfig', 'name']); - request.completionConfig.name = defaultValue1; - const expectedHeaderRequestParams = `completion_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCompletionConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCompletionConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCompletionConfig with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest() - ); - request.completionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest', ['completionConfig', 'name']); - request.completionConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCompletionConfig(request), expectedError); - }); - }); - - describe('getAttributesConfig', () => { - it('invokes getAttributesConfig without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAttributesConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAttributesConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.getAttributesConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getAttributesConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAttributesConfig without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAttributesConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAttributesConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.getAttributesConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getAttributesConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAttributesConfig with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAttributesConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAttributesConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getAttributesConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getAttributesConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAttributesConfig with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAttributesConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAttributesConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getAttributesConfig(request), expectedError); - }); - }); - - describe('updateAttributesConfig', () => { - it('invokes updateAttributesConfig without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest() - ); - request.attributesConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest', ['attributesConfig', 'name']); - request.attributesConfig.name = defaultValue1; - const expectedHeaderRequestParams = `attributes_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.updateAttributesConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateAttributesConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAttributesConfig without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest() - ); - request.attributesConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest', ['attributesConfig', 'name']); - request.attributesConfig.name = defaultValue1; - const expectedHeaderRequestParams = `attributes_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.updateAttributesConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateAttributesConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAttributesConfig with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest() - ); - request.attributesConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest', ['attributesConfig', 'name']); - request.attributesConfig.name = defaultValue1; - const expectedHeaderRequestParams = `attributes_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateAttributesConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateAttributesConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAttributesConfig with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest() - ); - request.attributesConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest', ['attributesConfig', 'name']); - request.attributesConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateAttributesConfig(request), expectedError); - }); - }); - - describe('addCatalogAttribute', () => { - it('invokes addCatalogAttribute without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.addCatalogAttribute = stubSimpleCall(expectedResponse); - const [response] = await client.addCatalogAttribute(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addCatalogAttribute without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.addCatalogAttribute = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addCatalogAttribute( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addCatalogAttribute with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addCatalogAttribute = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addCatalogAttribute(request), expectedError); - const actualRequest = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addCatalogAttribute with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addCatalogAttribute(request), expectedError); - }); - }); - - describe('removeCatalogAttribute', () => { - it('invokes removeCatalogAttribute without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.removeCatalogAttribute = stubSimpleCall(expectedResponse); - const [response] = await client.removeCatalogAttribute(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeCatalogAttribute without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.removeCatalogAttribute = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.removeCatalogAttribute( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeCatalogAttribute with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeCatalogAttribute = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.removeCatalogAttribute(request), expectedError); - const actualRequest = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeCatalogAttribute with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.removeCatalogAttribute(request), expectedError); - }); - }); - - describe('batchRemoveCatalogAttributes', () => { - it('invokes batchRemoveCatalogAttributes without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesResponse() - ); - client.innerApiCalls.batchRemoveCatalogAttributes = stubSimpleCall(expectedResponse); - const [response] = await client.batchRemoveCatalogAttributes(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchRemoveCatalogAttributes without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesResponse() - ); - client.innerApiCalls.batchRemoveCatalogAttributes = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchRemoveCatalogAttributes( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IBatchRemoveCatalogAttributesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchRemoveCatalogAttributes with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchRemoveCatalogAttributes = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.batchRemoveCatalogAttributes(request), expectedError); - const actualRequest = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchRemoveCatalogAttributes with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.batchRemoveCatalogAttributes(request), expectedError); - }); - }); - - describe('replaceCatalogAttribute', () => { - it('invokes replaceCatalogAttribute without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.replaceCatalogAttribute = stubSimpleCall(expectedResponse); - const [response] = await client.replaceCatalogAttribute(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes replaceCatalogAttribute without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.replaceCatalogAttribute = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.replaceCatalogAttribute( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes replaceCatalogAttribute with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.replaceCatalogAttribute = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.replaceCatalogAttribute(request), expectedError); - const actualRequest = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes replaceCatalogAttribute with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.replaceCatalogAttribute(request), expectedError); - }); - }); - - describe('listCatalogs', () => { - it('invokes listCatalogs without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - ]; - client.innerApiCalls.listCatalogs = stubSimpleCall(expectedResponse); - const [response] = await client.listCatalogs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCatalogs without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - ]; - client.innerApiCalls.listCatalogs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listCatalogs( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICatalog[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCatalogs with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listCatalogs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listCatalogs(request), expectedError); - const actualRequest = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCatalogsStream without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - ]; - client.descriptors.page.listCatalogs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listCatalogsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Catalog[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Catalog) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listCatalogs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCatalogs, request)); - assert( - (client.descriptors.page.listCatalogs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listCatalogsStream with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCatalogs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listCatalogsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Catalog[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Catalog) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listCatalogs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCatalogs, request)); - assert( - (client.descriptors.page.listCatalogs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCatalogs without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - ]; - client.descriptors.page.listCatalogs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.ICatalog[] = []; - const iterable = client.listCatalogsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listCatalogs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCatalogs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCatalogs with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCatalogs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listCatalogsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.ICatalog[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listCatalogs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCatalogs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('location', () => { - const fakePath = "/rendered/path/location"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.locationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.locationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath("projectValue", "locationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_completion_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_completion_service_v2alpha.ts.baseline deleted file mode 100644 index 5ff69dc5b518..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_completion_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1064 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as completionserviceModule from '../src/index.js'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.CompletionServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = completionserviceModule.v2alpha.CompletionServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = completionserviceModule.v2alpha.CompletionServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new completionserviceModule.v2alpha.CompletionServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new completionserviceModule.v2alpha.CompletionServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = completionserviceModule.v2alpha.CompletionServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.completionServiceStub, undefined); - await client.initialize(); - assert(client.completionServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.completionServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.completionServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - 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); - }); - }); - - describe('completeQuery', () => { - it('invokes completeQuery without error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CompleteQueryRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryResponse() - ); - client.innerApiCalls.completeQuery = stubSimpleCall(expectedResponse); - const [response] = await client.completeQuery(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes completeQuery without error using callback', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CompleteQueryRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryResponse() - ); - client.innerApiCalls.completeQuery = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.completeQuery( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICompleteQueryResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes completeQuery with error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CompleteQueryRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.completeQuery = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.completeQuery(request), expectedError); - const actualRequest = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes completeQuery with closed client', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CompleteQueryRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.completeQuery(request), expectedError); - }); - }); - - describe('importCompletionData', () => { - it('invokes importCompletionData without error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportCompletionDataRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportCompletionDataRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importCompletionData = stubLongRunningCall(expectedResponse); - const [operation] = await client.importCompletionData(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCompletionData without error using callback', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportCompletionDataRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportCompletionDataRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importCompletionData = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importCompletionData( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCompletionData with call error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportCompletionDataRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportCompletionDataRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importCompletionData = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.importCompletionData(request), expectedError); - const actualRequest = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCompletionData with LRO error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportCompletionDataRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportCompletionDataRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importCompletionData = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.importCompletionData(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportCompletionDataProgress without error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportCompletionDataProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportCompletionDataProgress with error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkImportCompletionDataProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_control_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_control_service_v2alpha.ts.baseline deleted file mode 100644 index f25a690821f2..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_control_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1514 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as controlserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.ControlServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = controlserviceModule.v2alpha.ControlServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = controlserviceModule.v2alpha.ControlServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new controlserviceModule.v2alpha.ControlServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new controlserviceModule.v2alpha.ControlServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new controlserviceModule.v2alpha.ControlServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = controlserviceModule.v2alpha.ControlServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.controlServiceStub, undefined); - await client.initialize(); - assert(client.controlServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.controlServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.controlServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - 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); - }); - }); - - describe('createControl', () => { - it('invokes createControl without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateControlRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.createControl = stubSimpleCall(expectedResponse); - const [response] = await client.createControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createControl without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateControlRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.createControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IControl|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createControl with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateControlRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createControl(request), expectedError); - const actualRequest = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createControl with closed client', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateControlRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createControl(request), expectedError); - }); - }); - - describe('deleteControl', () => { - it('invokes deleteControl without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteControl = stubSimpleCall(expectedResponse); - const [response] = await client.deleteControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteControl without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteControl( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteControl with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteControl(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteControl with closed client', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteControlRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteControl(request), expectedError); - }); - }); - - describe('updateControl', () => { - it('invokes updateControl without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateControlRequest() - ); - request.control ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateControlRequest', ['control', 'name']); - request.control.name = defaultValue1; - const expectedHeaderRequestParams = `control.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.updateControl = stubSimpleCall(expectedResponse); - const [response] = await client.updateControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateControl without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateControlRequest() - ); - request.control ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateControlRequest', ['control', 'name']); - request.control.name = defaultValue1; - const expectedHeaderRequestParams = `control.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.updateControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IControl|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateControl with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateControlRequest() - ); - request.control ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateControlRequest', ['control', 'name']); - request.control.name = defaultValue1; - const expectedHeaderRequestParams = `control.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateControl(request), expectedError); - const actualRequest = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateControl with closed client', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateControlRequest() - ); - request.control ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateControlRequest', ['control', 'name']); - request.control.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateControl(request), expectedError); - }); - }); - - describe('getControl', () => { - it('invokes getControl without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.getControl = stubSimpleCall(expectedResponse); - const [response] = await client.getControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getControl without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.getControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IControl|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getControl with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getControl(request), expectedError); - const actualRequest = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getControl with closed client', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetControlRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getControl(request), expectedError); - }); - }); - - describe('listControls', () => { - it('invokes listControls without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - ]; - client.innerApiCalls.listControls = stubSimpleCall(expectedResponse); - const [response] = await client.listControls(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listControls without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - ]; - client.innerApiCalls.listControls = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listControls( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IControl[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listControls with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listControls = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listControls(request), expectedError); - const actualRequest = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listControlsStream without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - ]; - client.descriptors.page.listControls.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listControlsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Control[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Control) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listControls.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listControls, request)); - assert( - (client.descriptors.page.listControls.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listControlsStream with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listControls.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listControlsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Control[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Control) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listControls.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listControls, request)); - assert( - (client.descriptors.page.listControls.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listControls without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - ]; - client.descriptors.page.listControls.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.IControl[] = []; - const iterable = client.listControlsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listControls.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listControls.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listControls with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listControls.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listControlsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.IControl[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listControls.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listControls.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_conversational_search_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_conversational_search_service_v2alpha.ts.baseline deleted file mode 100644 index 2c252f952650..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_conversational_search_service_v2alpha.ts.baseline +++ /dev/null @@ -1,931 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as conversationalsearchserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -describe('v2alpha.ConversationalSearchServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.conversationalSearchServiceStub, undefined); - await client.initialize(); - assert(client.conversationalSearchServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.conversationalSearchServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.conversationalSearchServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - 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); - }); - }); - - describe('conversationalSearch', () => { - it('invokes conversationalSearch without error', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ConversationalSearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchResponse() - ); - client.innerApiCalls.conversationalSearch = stubServerStreamingCall(expectedResponse); - const stream = client.conversationalSearch(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ConversationalSearchResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes conversationalSearch without error and gaxServerStreamingRetries enabled', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ConversationalSearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchResponse() - ); - client.innerApiCalls.conversationalSearch = stubServerStreamingCall(expectedResponse); - const stream = client.conversationalSearch(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ConversationalSearchResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes conversationalSearch with error', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ConversationalSearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.conversationalSearch = stubServerStreamingCall(undefined, expectedError); - const stream = client.conversationalSearch(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ConversationalSearchResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes conversationalSearch with closed client', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ConversationalSearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.conversationalSearch(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ConversationalSearchResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_generative_question_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_generative_question_service_v2alpha.ts.baseline deleted file mode 100644 index 57b41985a21f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_generative_question_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1334 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as generativequestionserviceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v2alpha.GenerativeQuestionServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.generativeQuestionServiceStub, undefined); - await client.initialize(); - assert(client.generativeQuestionServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.generativeQuestionServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.generativeQuestionServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - 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); - }); - }); - - describe('updateGenerativeQuestionsFeatureConfig', () => { - it('invokes updateGenerativeQuestionsFeatureConfig without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest() - ); - request.generativeQuestionsFeatureConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest', ['generativeQuestionsFeatureConfig', 'catalog']); - request.generativeQuestionsFeatureConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_questions_feature_config.catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionsFeatureConfig() - ); - client.innerApiCalls.updateGenerativeQuestionsFeatureConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateGenerativeQuestionsFeatureConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionsFeatureConfig without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest() - ); - request.generativeQuestionsFeatureConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest', ['generativeQuestionsFeatureConfig', 'catalog']); - request.generativeQuestionsFeatureConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_questions_feature_config.catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionsFeatureConfig() - ); - client.innerApiCalls.updateGenerativeQuestionsFeatureConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateGenerativeQuestionsFeatureConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IGenerativeQuestionsFeatureConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionsFeatureConfig with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest() - ); - request.generativeQuestionsFeatureConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest', ['generativeQuestionsFeatureConfig', 'catalog']); - request.generativeQuestionsFeatureConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_questions_feature_config.catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateGenerativeQuestionsFeatureConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateGenerativeQuestionsFeatureConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionsFeatureConfig with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest() - ); - request.generativeQuestionsFeatureConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest', ['generativeQuestionsFeatureConfig', 'catalog']); - request.generativeQuestionsFeatureConfig.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateGenerativeQuestionsFeatureConfig(request), expectedError); - }); - }); - - describe('getGenerativeQuestionsFeatureConfig', () => { - it('invokes getGenerativeQuestionsFeatureConfig without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionsFeatureConfig() - ); - client.innerApiCalls.getGenerativeQuestionsFeatureConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getGenerativeQuestionsFeatureConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGenerativeQuestionsFeatureConfig without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionsFeatureConfig() - ); - client.innerApiCalls.getGenerativeQuestionsFeatureConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getGenerativeQuestionsFeatureConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IGenerativeQuestionsFeatureConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGenerativeQuestionsFeatureConfig with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getGenerativeQuestionsFeatureConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getGenerativeQuestionsFeatureConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGenerativeQuestionsFeatureConfig with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getGenerativeQuestionsFeatureConfig(request), expectedError); - }); - }); - - describe('listGenerativeQuestionConfigs', () => { - it('invokes listGenerativeQuestionConfigs without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsResponse() - ); - client.innerApiCalls.listGenerativeQuestionConfigs = stubSimpleCall(expectedResponse); - const [response] = await client.listGenerativeQuestionConfigs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGenerativeQuestionConfigs without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsResponse() - ); - client.innerApiCalls.listGenerativeQuestionConfigs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listGenerativeQuestionConfigs( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IListGenerativeQuestionConfigsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGenerativeQuestionConfigs with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listGenerativeQuestionConfigs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listGenerativeQuestionConfigs(request), expectedError); - const actualRequest = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGenerativeQuestionConfigs with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listGenerativeQuestionConfigs(request), expectedError); - }); - }); - - describe('updateGenerativeQuestionConfig', () => { - it('invokes updateGenerativeQuestionConfig without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest() - ); - request.generativeQuestionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest', ['generativeQuestionConfig', 'catalog']); - request.generativeQuestionConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_question_config.catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionConfig() - ); - client.innerApiCalls.updateGenerativeQuestionConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateGenerativeQuestionConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionConfig without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest() - ); - request.generativeQuestionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest', ['generativeQuestionConfig', 'catalog']); - request.generativeQuestionConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_question_config.catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionConfig() - ); - client.innerApiCalls.updateGenerativeQuestionConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateGenerativeQuestionConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IGenerativeQuestionConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionConfig with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest() - ); - request.generativeQuestionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest', ['generativeQuestionConfig', 'catalog']); - request.generativeQuestionConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_question_config.catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateGenerativeQuestionConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateGenerativeQuestionConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionConfig with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest() - ); - request.generativeQuestionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest', ['generativeQuestionConfig', 'catalog']); - request.generativeQuestionConfig.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateGenerativeQuestionConfig(request), expectedError); - }); - }); - - describe('batchUpdateGenerativeQuestionConfigs', () => { - it('invokes batchUpdateGenerativeQuestionConfigs without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsResponse() - ); - client.innerApiCalls.batchUpdateGenerativeQuestionConfigs = stubSimpleCall(expectedResponse); - const [response] = await client.batchUpdateGenerativeQuestionConfigs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchUpdateGenerativeQuestionConfigs without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsResponse() - ); - client.innerApiCalls.batchUpdateGenerativeQuestionConfigs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchUpdateGenerativeQuestionConfigs( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IBatchUpdateGenerativeQuestionConfigsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchUpdateGenerativeQuestionConfigs with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchUpdateGenerativeQuestionConfigs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.batchUpdateGenerativeQuestionConfigs(request), expectedError); - const actualRequest = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchUpdateGenerativeQuestionConfigs with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.batchUpdateGenerativeQuestionConfigs(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_merchant_center_account_link_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_merchant_center_account_link_service_v2alpha.ts.baseline deleted file mode 100644 index d186919c1d11..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_merchant_center_account_link_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1172 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as merchantcenteraccountlinkserviceModule from '../src/index.js'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.MerchantCenterAccountLinkServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.merchantCenterAccountLinkServiceStub, undefined); - await client.initialize(); - assert(client.merchantCenterAccountLinkServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.merchantCenterAccountLinkServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.merchantCenterAccountLinkServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - 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); - }); - }); - - describe('listMerchantCenterAccountLinks', () => { - it('invokes listMerchantCenterAccountLinks without error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksResponse() - ); - client.innerApiCalls.listMerchantCenterAccountLinks = stubSimpleCall(expectedResponse); - const [response] = await client.listMerchantCenterAccountLinks(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMerchantCenterAccountLinks without error using callback', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksResponse() - ); - client.innerApiCalls.listMerchantCenterAccountLinks = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listMerchantCenterAccountLinks( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IListMerchantCenterAccountLinksResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMerchantCenterAccountLinks with error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listMerchantCenterAccountLinks = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listMerchantCenterAccountLinks(request), expectedError); - const actualRequest = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMerchantCenterAccountLinks with closed client', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listMerchantCenterAccountLinks(request), expectedError); - }); - }); - - describe('deleteMerchantCenterAccountLink', () => { - it('invokes deleteMerchantCenterAccountLink without error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteMerchantCenterAccountLink = stubSimpleCall(expectedResponse); - const [response] = await client.deleteMerchantCenterAccountLink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMerchantCenterAccountLink without error using callback', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteMerchantCenterAccountLink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteMerchantCenterAccountLink( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMerchantCenterAccountLink with error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteMerchantCenterAccountLink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteMerchantCenterAccountLink(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMerchantCenterAccountLink with closed client', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteMerchantCenterAccountLink(request), expectedError); - }); - }); - - describe('createMerchantCenterAccountLink', () => { - it('invokes createMerchantCenterAccountLink without error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createMerchantCenterAccountLink = stubLongRunningCall(expectedResponse); - const [operation] = await client.createMerchantCenterAccountLink(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMerchantCenterAccountLink without error using callback', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createMerchantCenterAccountLink = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createMerchantCenterAccountLink( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMerchantCenterAccountLink with call error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createMerchantCenterAccountLink = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.createMerchantCenterAccountLink(request), expectedError); - const actualRequest = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMerchantCenterAccountLink with LRO error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createMerchantCenterAccountLink = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.createMerchantCenterAccountLink(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateMerchantCenterAccountLinkProgress without error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateMerchantCenterAccountLinkProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateMerchantCenterAccountLinkProgress with error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCreateMerchantCenterAccountLinkProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_model_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_model_service_v2alpha.ts.baseline deleted file mode 100644 index 05617e930de0..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_model_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1946 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as modelserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.ModelServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = modelserviceModule.v2alpha.ModelServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = modelserviceModule.v2alpha.ModelServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new modelserviceModule.v2alpha.ModelServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new modelserviceModule.v2alpha.ModelServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new modelserviceModule.v2alpha.ModelServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = modelserviceModule.v2alpha.ModelServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.modelServiceStub, undefined); - await client.initialize(); - assert(client.modelServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.modelServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.modelServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - 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); - }); - }); - - describe('getModel', () => { - it('invokes getModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.getModel = stubSimpleCall(expectedResponse); - const [response] = await client.getModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.getModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getModel( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getModel(request), expectedError); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetModelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getModel(request), expectedError); - }); - }); - - describe('pauseModel', () => { - it('invokes pauseModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PauseModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PauseModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.pauseModel = stubSimpleCall(expectedResponse); - const [response] = await client.pauseModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PauseModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PauseModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.pauseModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pauseModel( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PauseModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PauseModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.pauseModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pauseModel(request), expectedError); - const actualRequest = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PauseModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PauseModelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pauseModel(request), expectedError); - }); - }); - - describe('resumeModel', () => { - it('invokes resumeModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ResumeModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ResumeModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.resumeModel = stubSimpleCall(expectedResponse); - const [response] = await client.resumeModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ResumeModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ResumeModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.resumeModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resumeModel( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ResumeModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ResumeModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.resumeModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.resumeModel(request), expectedError); - const actualRequest = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ResumeModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ResumeModelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.resumeModel(request), expectedError); - }); - }); - - describe('deleteModel', () => { - it('invokes deleteModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteModel = stubSimpleCall(expectedResponse); - const [response] = await client.deleteModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteModel( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteModel(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteModelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteModel(request), expectedError); - }); - }); - - describe('updateModel', () => { - it('invokes updateModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateModelRequest() - ); - request.model ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateModelRequest', ['model', 'name']); - request.model.name = defaultValue1; - const expectedHeaderRequestParams = `model.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.updateModel = stubSimpleCall(expectedResponse); - const [response] = await client.updateModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateModelRequest() - ); - request.model ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateModelRequest', ['model', 'name']); - request.model.name = defaultValue1; - const expectedHeaderRequestParams = `model.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.updateModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateModel( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateModelRequest() - ); - request.model ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateModelRequest', ['model', 'name']); - request.model.name = defaultValue1; - const expectedHeaderRequestParams = `model.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateModel(request), expectedError); - const actualRequest = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateModelRequest() - ); - request.model ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateModelRequest', ['model', 'name']); - request.model.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateModel(request), expectedError); - }); - }); - - describe('createModel', () => { - it('invokes createModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateModelRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createModel = stubLongRunningCall(expectedResponse); - const [operation] = await client.createModel(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateModelRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createModel = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createModel( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createModel with call error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateModelRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createModel = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.createModel(request), expectedError); - const actualRequest = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createModel with LRO error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateModelRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createModel = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.createModel(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateModelProgress without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateModelProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateModelProgress with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCreateModelProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('tuneModel', () => { - it('invokes tuneModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.TuneModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.TuneModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.tuneModel = stubLongRunningCall(expectedResponse); - const [operation] = await client.tuneModel(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes tuneModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.TuneModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.TuneModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.tuneModel = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.tuneModel( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes tuneModel with call error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.TuneModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.TuneModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.tuneModel = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.tuneModel(request), expectedError); - const actualRequest = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes tuneModel with LRO error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.TuneModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.TuneModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.tuneModel = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.tuneModel(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkTuneModelProgress without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkTuneModelProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkTuneModelProgress with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkTuneModelProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listModels', () => { - it('invokes listModels without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - ]; - client.innerApiCalls.listModels = stubSimpleCall(expectedResponse); - const [response] = await client.listModels(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModels without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - ]; - client.innerApiCalls.listModels = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listModels( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModels with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listModels = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listModels(request), expectedError); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModelsStream without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - ]; - client.descriptors.page.listModels.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listModelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Model[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Model) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listModels, request)); - assert( - (client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listModelsStream with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listModels.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listModelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Model[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Model) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listModels, request)); - assert( - (client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listModels without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - ]; - client.descriptors.page.listModels.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.IModel[] = []; - const iterable = client.listModelsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listModels with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listModels.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listModelsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.IModel[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_prediction_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_prediction_service_v2alpha.ts.baseline deleted file mode 100644 index eca48b4b3719..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_prediction_service_v2alpha.ts.baseline +++ /dev/null @@ -1,894 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as predictionserviceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v2alpha.PredictionServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = predictionserviceModule.v2alpha.PredictionServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = predictionserviceModule.v2alpha.PredictionServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new predictionserviceModule.v2alpha.PredictionServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = predictionserviceModule.v2alpha.PredictionServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.predictionServiceStub, undefined); - await client.initialize(); - assert(client.predictionServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.predictionServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.predictionServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - 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); - }); - }); - - describe('predict', () => { - it('invokes predict without error', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PredictRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictResponse() - ); - client.innerApiCalls.predict = stubSimpleCall(expectedResponse); - const [response] = await client.predict(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes predict without error using callback', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PredictRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictResponse() - ); - client.innerApiCalls.predict = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.predict( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IPredictResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes predict with error', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PredictRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.predict = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.predict(request), expectedError); - const actualRequest = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes predict with closed client', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PredictRequest', ['placement']); - request.placement = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.predict(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_product_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_product_service_v2alpha.ts.baseline deleted file mode 100644 index 0d4fddb425d3..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_product_service_v2alpha.ts.baseline +++ /dev/null @@ -1,2766 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as productserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.ProductServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = productserviceModule.v2alpha.ProductServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = productserviceModule.v2alpha.ProductServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new productserviceModule.v2alpha.ProductServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new productserviceModule.v2alpha.ProductServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new productserviceModule.v2alpha.ProductServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = productserviceModule.v2alpha.ProductServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.productServiceStub, undefined); - await client.initialize(); - assert(client.productServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.productServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.productServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - 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); - }); - }); - - describe('createProduct', () => { - it('invokes createProduct without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateProductRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.createProduct = stubSimpleCall(expectedResponse); - const [response] = await client.createProduct(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createProduct without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateProductRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.createProduct = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createProduct( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProduct|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createProduct with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateProductRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createProduct = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createProduct(request), expectedError); - const actualRequest = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createProduct with closed client', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateProductRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createProduct(request), expectedError); - }); - }); - - describe('getProduct', () => { - it('invokes getProduct without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.getProduct = stubSimpleCall(expectedResponse); - const [response] = await client.getProduct(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProduct without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.getProduct = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getProduct( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProduct|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProduct with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getProduct = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getProduct(request), expectedError); - const actualRequest = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProduct with closed client', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProductRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getProduct(request), expectedError); - }); - }); - - describe('updateProduct', () => { - it('invokes updateProduct without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateProductRequest() - ); - request.product ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateProductRequest', ['product', 'name']); - request.product.name = defaultValue1; - const expectedHeaderRequestParams = `product.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.updateProduct = stubSimpleCall(expectedResponse); - const [response] = await client.updateProduct(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProduct without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateProductRequest() - ); - request.product ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateProductRequest', ['product', 'name']); - request.product.name = defaultValue1; - const expectedHeaderRequestParams = `product.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.updateProduct = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateProduct( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProduct|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProduct with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateProductRequest() - ); - request.product ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateProductRequest', ['product', 'name']); - request.product.name = defaultValue1; - const expectedHeaderRequestParams = `product.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateProduct = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateProduct(request), expectedError); - const actualRequest = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProduct with closed client', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateProductRequest() - ); - request.product ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateProductRequest', ['product', 'name']); - request.product.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateProduct(request), expectedError); - }); - }); - - describe('deleteProduct', () => { - it('invokes deleteProduct without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteProduct = stubSimpleCall(expectedResponse); - const [response] = await client.deleteProduct(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteProduct without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteProduct = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteProduct( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteProduct with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteProduct = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteProduct(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteProduct with closed client', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteProductRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteProduct(request), expectedError); - }); - }); - - describe('purgeProducts', () => { - it('invokes purgeProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.purgeProducts = stubLongRunningCall(expectedResponse); - const [operation] = await client.purgeProducts(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeProducts without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.purgeProducts = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.purgeProducts( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeProducts with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeProducts = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.purgeProducts(request), expectedError); - const actualRequest = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeProducts with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeProducts = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.purgeProducts(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkPurgeProductsProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkPurgeProductsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkPurgeProductsProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkPurgeProductsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('importProducts', () => { - it('invokes importProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importProducts = stubLongRunningCall(expectedResponse); - const [operation] = await client.importProducts(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importProducts without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importProducts = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importProducts( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importProducts with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importProducts = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.importProducts(request), expectedError); - const actualRequest = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importProducts with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importProducts = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.importProducts(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportProductsProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportProductsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportProductsProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkImportProductsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('exportProducts', () => { - it('invokes exportProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportProducts = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportProducts(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportProducts without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportProducts = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportProducts( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportProducts with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportProducts = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportProducts(request), expectedError); - const actualRequest = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportProducts with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportProducts = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportProducts(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportProductsProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportProductsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportProductsProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportProductsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('setInventory', () => { - it('invokes setInventory without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetInventoryRequest() - ); - request.inventory ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetInventoryRequest', ['inventory', 'name']); - request.inventory.name = defaultValue1; - const expectedHeaderRequestParams = `inventory.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.setInventory = stubLongRunningCall(expectedResponse); - const [operation] = await client.setInventory(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setInventory without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetInventoryRequest() - ); - request.inventory ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetInventoryRequest', ['inventory', 'name']); - request.inventory.name = defaultValue1; - const expectedHeaderRequestParams = `inventory.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.setInventory = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setInventory( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setInventory with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetInventoryRequest() - ); - request.inventory ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetInventoryRequest', ['inventory', 'name']); - request.inventory.name = defaultValue1; - const expectedHeaderRequestParams = `inventory.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.setInventory = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.setInventory(request), expectedError); - const actualRequest = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setInventory with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetInventoryRequest() - ); - request.inventory ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetInventoryRequest', ['inventory', 'name']); - request.inventory.name = defaultValue1; - const expectedHeaderRequestParams = `inventory.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.setInventory = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.setInventory(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkSetInventoryProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkSetInventoryProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkSetInventoryProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkSetInventoryProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('addFulfillmentPlaces', () => { - it('invokes addFulfillmentPlaces without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.addFulfillmentPlaces = stubLongRunningCall(expectedResponse); - const [operation] = await client.addFulfillmentPlaces(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addFulfillmentPlaces without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.addFulfillmentPlaces = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addFulfillmentPlaces( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addFulfillmentPlaces with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addFulfillmentPlaces = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.addFulfillmentPlaces(request), expectedError); - const actualRequest = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addFulfillmentPlaces with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addFulfillmentPlaces = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.addFulfillmentPlaces(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkAddFulfillmentPlacesProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkAddFulfillmentPlacesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkAddFulfillmentPlacesProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkAddFulfillmentPlacesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('removeFulfillmentPlaces', () => { - it('invokes removeFulfillmentPlaces without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.removeFulfillmentPlaces = stubLongRunningCall(expectedResponse); - const [operation] = await client.removeFulfillmentPlaces(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeFulfillmentPlaces without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.removeFulfillmentPlaces = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.removeFulfillmentPlaces( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeFulfillmentPlaces with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeFulfillmentPlaces = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.removeFulfillmentPlaces(request), expectedError); - const actualRequest = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeFulfillmentPlaces with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeFulfillmentPlaces = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.removeFulfillmentPlaces(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkRemoveFulfillmentPlacesProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkRemoveFulfillmentPlacesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkRemoveFulfillmentPlacesProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkRemoveFulfillmentPlacesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('addLocalInventories', () => { - it('invokes addLocalInventories without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.addLocalInventories = stubLongRunningCall(expectedResponse); - const [operation] = await client.addLocalInventories(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addLocalInventories without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.addLocalInventories = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addLocalInventories( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addLocalInventories with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addLocalInventories = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.addLocalInventories(request), expectedError); - const actualRequest = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addLocalInventories with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addLocalInventories = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.addLocalInventories(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkAddLocalInventoriesProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkAddLocalInventoriesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkAddLocalInventoriesProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkAddLocalInventoriesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('removeLocalInventories', () => { - it('invokes removeLocalInventories without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.removeLocalInventories = stubLongRunningCall(expectedResponse); - const [operation] = await client.removeLocalInventories(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeLocalInventories without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.removeLocalInventories = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.removeLocalInventories( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeLocalInventories with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeLocalInventories = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.removeLocalInventories(request), expectedError); - const actualRequest = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeLocalInventories with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeLocalInventories = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.removeLocalInventories(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkRemoveLocalInventoriesProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkRemoveLocalInventoriesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkRemoveLocalInventoriesProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkRemoveLocalInventoriesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listProducts', () => { - it('invokes listProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - ]; - client.innerApiCalls.listProducts = stubSimpleCall(expectedResponse); - const [response] = await client.listProducts(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProducts without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - ]; - client.innerApiCalls.listProducts = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listProducts( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProduct[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProducts with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listProducts = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listProducts(request), expectedError); - const actualRequest = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProductsStream without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - ]; - client.descriptors.page.listProducts.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listProductsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Product[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Product) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listProducts.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listProducts, request)); - assert( - (client.descriptors.page.listProducts.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listProductsStream with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listProducts.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listProductsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Product[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Product) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listProducts.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listProducts, request)); - assert( - (client.descriptors.page.listProducts.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - ]; - client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.IProduct[] = []; - const iterable = client.listProductsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listProducts.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listProducts.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listProducts with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listProductsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.IProduct[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listProducts.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listProducts.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_project_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_project_service_v2alpha.ts.baseline deleted file mode 100644 index bc734d97200c..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_project_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1750 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as projectserviceModule from '../src/index.js'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.ProjectServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = projectserviceModule.v2alpha.ProjectServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = projectserviceModule.v2alpha.ProjectServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new projectserviceModule.v2alpha.ProjectServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new projectserviceModule.v2alpha.ProjectServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = projectserviceModule.v2alpha.ProjectServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.projectServiceStub, undefined); - await client.initialize(); - assert(client.projectServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.projectServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.projectServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - 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); - }); - }); - - describe('getProject', () => { - it('invokes getProject without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProjectRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProjectRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Project() - ); - client.innerApiCalls.getProject = stubSimpleCall(expectedResponse); - const [response] = await client.getProject(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProject without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProjectRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProjectRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Project() - ); - client.innerApiCalls.getProject = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getProject( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProject|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProject with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProjectRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProjectRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getProject = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getProject(request), expectedError); - const actualRequest = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProject with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProjectRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProjectRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getProject(request), expectedError); - }); - }); - - describe('acceptTerms', () => { - it('invokes acceptTerms without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AcceptTermsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AcceptTermsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Project() - ); - client.innerApiCalls.acceptTerms = stubSimpleCall(expectedResponse); - const [response] = await client.acceptTerms(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acceptTerms without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AcceptTermsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AcceptTermsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Project() - ); - client.innerApiCalls.acceptTerms = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.acceptTerms( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProject|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acceptTerms with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AcceptTermsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AcceptTermsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.acceptTerms = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.acceptTerms(request), expectedError); - const actualRequest = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acceptTerms with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AcceptTermsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AcceptTermsRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.acceptTerms(request), expectedError); - }); - }); - - describe('listEnrolledSolutions', () => { - it('invokes listEnrolledSolutions without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsResponse() - ); - client.innerApiCalls.listEnrolledSolutions = stubSimpleCall(expectedResponse); - const [response] = await client.listEnrolledSolutions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEnrolledSolutions without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsResponse() - ); - client.innerApiCalls.listEnrolledSolutions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listEnrolledSolutions( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IListEnrolledSolutionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEnrolledSolutions with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listEnrolledSolutions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listEnrolledSolutions(request), expectedError); - const actualRequest = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEnrolledSolutions with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listEnrolledSolutions(request), expectedError); - }); - }); - - describe('getLoggingConfig', () => { - it('invokes getLoggingConfig without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetLoggingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetLoggingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.LoggingConfig() - ); - client.innerApiCalls.getLoggingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getLoggingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLoggingConfig without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetLoggingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetLoggingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.LoggingConfig() - ); - client.innerApiCalls.getLoggingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getLoggingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ILoggingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLoggingConfig with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetLoggingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetLoggingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getLoggingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getLoggingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLoggingConfig with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetLoggingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetLoggingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getLoggingConfig(request), expectedError); - }); - }); - - describe('updateLoggingConfig', () => { - it('invokes updateLoggingConfig without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest() - ); - request.loggingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest', ['loggingConfig', 'name']); - request.loggingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `logging_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.LoggingConfig() - ); - client.innerApiCalls.updateLoggingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateLoggingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLoggingConfig without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest() - ); - request.loggingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest', ['loggingConfig', 'name']); - request.loggingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `logging_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.LoggingConfig() - ); - client.innerApiCalls.updateLoggingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateLoggingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ILoggingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLoggingConfig with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest() - ); - request.loggingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest', ['loggingConfig', 'name']); - request.loggingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `logging_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateLoggingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateLoggingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLoggingConfig with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest() - ); - request.loggingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest', ['loggingConfig', 'name']); - request.loggingConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateLoggingConfig(request), expectedError); - }); - }); - - describe('getAlertConfig', () => { - it('invokes getAlertConfig without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAlertConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAlertConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AlertConfig() - ); - client.innerApiCalls.getAlertConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getAlertConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertConfig without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAlertConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAlertConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AlertConfig() - ); - client.innerApiCalls.getAlertConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getAlertConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAlertConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertConfig with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAlertConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAlertConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getAlertConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getAlertConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertConfig with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAlertConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAlertConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getAlertConfig(request), expectedError); - }); - }); - - describe('updateAlertConfig', () => { - it('invokes updateAlertConfig without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAlertConfigRequest() - ); - request.alertConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAlertConfigRequest', ['alertConfig', 'name']); - request.alertConfig.name = defaultValue1; - const expectedHeaderRequestParams = `alert_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AlertConfig() - ); - client.innerApiCalls.updateAlertConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateAlertConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertConfig without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAlertConfigRequest() - ); - request.alertConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAlertConfigRequest', ['alertConfig', 'name']); - request.alertConfig.name = defaultValue1; - const expectedHeaderRequestParams = `alert_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AlertConfig() - ); - client.innerApiCalls.updateAlertConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateAlertConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAlertConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertConfig with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAlertConfigRequest() - ); - request.alertConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAlertConfigRequest', ['alertConfig', 'name']); - request.alertConfig.name = defaultValue1; - const expectedHeaderRequestParams = `alert_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateAlertConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateAlertConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertConfig with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAlertConfigRequest() - ); - request.alertConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAlertConfigRequest', ['alertConfig', 'name']); - request.alertConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateAlertConfig(request), expectedError); - }); - }); - - describe('enrollSolution', () => { - it('invokes enrollSolution without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.EnrollSolutionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.EnrollSolutionRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.enrollSolution = stubLongRunningCall(expectedResponse); - const [operation] = await client.enrollSolution(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enrollSolution without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.EnrollSolutionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.EnrollSolutionRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.enrollSolution = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.enrollSolution( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enrollSolution with call error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.EnrollSolutionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.EnrollSolutionRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.enrollSolution = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.enrollSolution(request), expectedError); - const actualRequest = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enrollSolution with LRO error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.EnrollSolutionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.EnrollSolutionRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.enrollSolution = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.enrollSolution(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkEnrollSolutionProgress without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkEnrollSolutionProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkEnrollSolutionProgress with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkEnrollSolutionProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_search_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_search_service_v2alpha.ts.baseline deleted file mode 100644 index b3111ae687a7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_search_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1132 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as searchserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.SearchServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = searchserviceModule.v2alpha.SearchServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = searchserviceModule.v2alpha.SearchServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new searchserviceModule.v2alpha.SearchServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new searchserviceModule.v2alpha.SearchServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new searchserviceModule.v2alpha.SearchServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = searchserviceModule.v2alpha.SearchServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.searchServiceStub, undefined); - await client.initialize(); - assert(client.searchServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.searchServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.searchServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - 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); - }); - }); - - describe('search', () => { - it('invokes search without error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - ]; - client.innerApiCalls.search = stubSimpleCall(expectedResponse); - const [response] = await client.search(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes search without error using callback', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - ]; - client.innerApiCalls.search = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.search( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.SearchResponse.ISearchResult[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes search with error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.search = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.search(request), expectedError); - const actualRequest = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchStream without error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - ]; - client.descriptors.page.search.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.searchStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.search.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.search, request)); - assert( - (client.descriptors.page.search.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes searchStream with error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.search.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.searchStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.search.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.search, request)); - assert( - (client.descriptors.page.search.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with search without error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - ]; - client.descriptors.page.search.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.SearchResponse.ISearchResult[] = []; - const iterable = client.searchAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.search.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.search.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with search with error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.search.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.searchAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.SearchResponse.ISearchResult[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.search.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.search.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('experiment', () => { - const fakePath = "/rendered/path/experiment"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - experiment: "experimentValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.experimentPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.experimentPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('experimentPath', () => { - const result = client.experimentPath("projectValue", "locationValue", "catalogValue", "experimentValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.experimentPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromExperimentName', () => { - const result = client.matchProjectFromExperimentName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.experimentPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromExperimentName', () => { - const result = client.matchLocationFromExperimentName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.experimentPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromExperimentName', () => { - const result = client.matchCatalogFromExperimentName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.experimentPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExperimentFromExperimentName', () => { - const result = client.matchExperimentFromExperimentName(fakePath); - assert.strictEqual(result, "experimentValue"); - assert((client.pathTemplates.experimentPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_serving_config_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_serving_config_service_v2alpha.ts.baseline deleted file mode 100644 index ae2f7b6662df..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_serving_config_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1730 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as servingconfigserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.ServingConfigServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = servingconfigserviceModule.v2alpha.ServingConfigServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = servingconfigserviceModule.v2alpha.ServingConfigServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = servingconfigserviceModule.v2alpha.ServingConfigServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.servingConfigServiceStub, undefined); - await client.initialize(); - assert(client.servingConfigServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.servingConfigServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.servingConfigServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - 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); - }); - }); - - describe('createServingConfig', () => { - it('invokes createServingConfig without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateServingConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.createServingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.createServingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServingConfig without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateServingConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.createServingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createServingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServingConfig with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateServingConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createServingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createServingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServingConfig with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateServingConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createServingConfig(request), expectedError); - }); - }); - - describe('deleteServingConfig', () => { - it('invokes deleteServingConfig without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteServingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.deleteServingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServingConfig without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteServingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteServingConfig( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServingConfig with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteServingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteServingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServingConfig with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteServingConfig(request), expectedError); - }); - }); - - describe('updateServingConfig', () => { - it('invokes updateServingConfig without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateServingConfigRequest() - ); - request.servingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateServingConfigRequest', ['servingConfig', 'name']); - request.servingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `serving_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.updateServingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateServingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServingConfig without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateServingConfigRequest() - ); - request.servingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateServingConfigRequest', ['servingConfig', 'name']); - request.servingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `serving_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.updateServingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateServingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServingConfig with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateServingConfigRequest() - ); - request.servingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateServingConfigRequest', ['servingConfig', 'name']); - request.servingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `serving_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateServingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateServingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServingConfig with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateServingConfigRequest() - ); - request.servingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateServingConfigRequest', ['servingConfig', 'name']); - request.servingConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateServingConfig(request), expectedError); - }); - }); - - describe('getServingConfig', () => { - it('invokes getServingConfig without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.getServingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getServingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServingConfig without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.getServingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getServingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServingConfig with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getServingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getServingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServingConfig with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getServingConfig(request), expectedError); - }); - }); - - describe('addControl', () => { - it('invokes addControl without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.addControl = stubSimpleCall(expectedResponse); - const [response] = await client.addControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addControl without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.addControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addControl with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addControl(request), expectedError); - const actualRequest = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addControl with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addControl(request), expectedError); - }); - }); - - describe('removeControl', () => { - it('invokes removeControl without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.removeControl = stubSimpleCall(expectedResponse); - const [response] = await client.removeControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeControl without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.removeControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.removeControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeControl with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.removeControl(request), expectedError); - const actualRequest = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeControl with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.removeControl(request), expectedError); - }); - }); - - describe('listServingConfigs', () => { - it('invokes listServingConfigs without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - ]; - client.innerApiCalls.listServingConfigs = stubSimpleCall(expectedResponse); - const [response] = await client.listServingConfigs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServingConfigs without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - ]; - client.innerApiCalls.listServingConfigs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServingConfigs( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServingConfigs with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServingConfigs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServingConfigs(request), expectedError); - const actualRequest = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServingConfigsStream without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - ]; - client.descriptors.page.listServingConfigs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listServingConfigsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.ServingConfig[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ServingConfig) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listServingConfigs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServingConfigs, request)); - assert( - (client.descriptors.page.listServingConfigs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listServingConfigsStream with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServingConfigs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listServingConfigsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.ServingConfig[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ServingConfig) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listServingConfigs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServingConfigs, request)); - assert( - (client.descriptors.page.listServingConfigs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServingConfigs without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - ]; - client.descriptors.page.listServingConfigs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.IServingConfig[] = []; - const iterable = client.listServingConfigsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listServingConfigs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServingConfigs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServingConfigs with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServingConfigs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listServingConfigsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.IServingConfig[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listServingConfigs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServingConfigs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_user_event_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_user_event_service_v2alpha.ts.baseline deleted file mode 100644 index 07bb9d1fbf1a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/esm/test/gapic_user_event_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1634 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as usereventserviceModule from '../src/index.js'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.UserEventServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = usereventserviceModule.v2alpha.UserEventServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = usereventserviceModule.v2alpha.UserEventServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new usereventserviceModule.v2alpha.UserEventServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = usereventserviceModule.v2alpha.UserEventServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.userEventServiceStub, undefined); - await client.initialize(); - assert(client.userEventServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.userEventServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.userEventServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - 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); - }); - }); - - describe('writeUserEvent', () => { - it('invokes writeUserEvent without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.WriteUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.WriteUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UserEvent() - ); - client.innerApiCalls.writeUserEvent = stubSimpleCall(expectedResponse); - const [response] = await client.writeUserEvent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes writeUserEvent without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.WriteUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.WriteUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UserEvent() - ); - client.innerApiCalls.writeUserEvent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.writeUserEvent( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IUserEvent|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes writeUserEvent with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.WriteUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.WriteUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.writeUserEvent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.writeUserEvent(request), expectedError); - const actualRequest = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes writeUserEvent with closed client', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.WriteUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.WriteUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.writeUserEvent(request), expectedError); - }); - }); - - describe('collectUserEvent', () => { - it('invokes collectUserEvent without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CollectUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CollectUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.HttpBody() - ); - client.innerApiCalls.collectUserEvent = stubSimpleCall(expectedResponse); - const [response] = await client.collectUserEvent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes collectUserEvent without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CollectUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CollectUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.HttpBody() - ); - client.innerApiCalls.collectUserEvent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.collectUserEvent( - request, - (err?: Error|null, result?: protos.google.api.IHttpBody|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes collectUserEvent with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CollectUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CollectUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.collectUserEvent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.collectUserEvent(request), expectedError); - const actualRequest = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes collectUserEvent with closed client', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CollectUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CollectUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.collectUserEvent(request), expectedError); - }); - }); - - describe('purgeUserEvents', () => { - it('invokes purgeUserEvents without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.purgeUserEvents = stubLongRunningCall(expectedResponse); - const [operation] = await client.purgeUserEvents(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeUserEvents without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.purgeUserEvents = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.purgeUserEvents( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeUserEvents with call error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeUserEvents = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.purgeUserEvents(request), expectedError); - const actualRequest = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeUserEvents with LRO error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeUserEvents = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.purgeUserEvents(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkPurgeUserEventsProgress without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkPurgeUserEventsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkPurgeUserEventsProgress with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkPurgeUserEventsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('importUserEvents', () => { - it('invokes importUserEvents without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importUserEvents = stubLongRunningCall(expectedResponse); - const [operation] = await client.importUserEvents(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importUserEvents without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importUserEvents = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importUserEvents( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importUserEvents with call error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importUserEvents = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.importUserEvents(request), expectedError); - const actualRequest = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importUserEvents with LRO error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importUserEvents = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.importUserEvents(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportUserEventsProgress without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportUserEventsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportUserEventsProgress with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkImportUserEventsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('exportUserEvents', () => { - it('invokes exportUserEvents without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportUserEvents = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportUserEvents(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportUserEvents without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportUserEvents = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportUserEvents( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportUserEvents with call error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportUserEvents = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportUserEvents(request), expectedError); - const actualRequest = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportUserEvents with LRO error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportUserEvents = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportUserEvents(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportUserEventsProgress without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportUserEventsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportUserEventsProgress with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportUserEventsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('rejoinUserEvents', () => { - it('invokes rejoinUserEvents without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RejoinUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RejoinUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.rejoinUserEvents = stubLongRunningCall(expectedResponse); - const [operation] = await client.rejoinUserEvents(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rejoinUserEvents without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RejoinUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RejoinUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.rejoinUserEvents = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rejoinUserEvents( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rejoinUserEvents with call error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RejoinUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RejoinUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rejoinUserEvents = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.rejoinUserEvents(request), expectedError); - const actualRequest = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rejoinUserEvents with LRO error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RejoinUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RejoinUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rejoinUserEvents = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.rejoinUserEvents(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkRejoinUserEventsProgress without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkRejoinUserEventsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkRejoinUserEventsProgress with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkRejoinUserEventsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/package.json b/core/generator/gapic-generator-typescript/baselines/retail-esm/package.json index 4dad3cdc8951..4f420933496b 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/retail-esm/package.json @@ -74,12 +74,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -94,21 +88,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/retail-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/retail-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/retail-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/retail-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/retail/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/retail/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/retail/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/retail/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/retail/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/retail/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/retail/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/retail/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/retail/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/retail/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/retail/package.json b/core/generator/gapic-generator-typescript/baselines/retail/package.json index cce57a59a986..4ea3f4da024b 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail/package.json +++ b/core/generator/gapic-generator-typescript/baselines/retail/package.json @@ -44,27 +44,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/retail/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/retail/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index ddd81b9f0d86..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const retail = require('retail'); - -function main() { - const analyticsServiceClient = new retail.AnalyticsServiceClient(); - const branchServiceClient = new retail.BranchServiceClient(); - const catalogServiceClient = new retail.CatalogServiceClient(); - const completionServiceClient = new retail.CompletionServiceClient(); - const controlServiceClient = new retail.ControlServiceClient(); - const conversationalSearchServiceClient = new retail.ConversationalSearchServiceClient(); - const generativeQuestionServiceClient = new retail.GenerativeQuestionServiceClient(); - const merchantCenterAccountLinkServiceClient = new retail.MerchantCenterAccountLinkServiceClient(); - const modelServiceClient = new retail.ModelServiceClient(); - const predictionServiceClient = new retail.PredictionServiceClient(); - const productServiceClient = new retail.ProductServiceClient(); - const projectServiceClient = new retail.ProjectServiceClient(); - const searchServiceClient = new retail.SearchServiceClient(); - const servingConfigServiceClient = new retail.ServingConfigServiceClient(); - const userEventServiceClient = new retail.UserEventServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 060b8503bc11..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {AnalyticsServiceClient, BranchServiceClient, CatalogServiceClient, CompletionServiceClient, ControlServiceClient, ConversationalSearchServiceClient, GenerativeQuestionServiceClient, MerchantCenterAccountLinkServiceClient, ModelServiceClient, PredictionServiceClient, ProductServiceClient, ProjectServiceClient, SearchServiceClient, ServingConfigServiceClient, UserEventServiceClient} from 'retail'; - -// check that the client class type name can be used -function doStuffWithAnalyticsServiceClient(client: AnalyticsServiceClient) { - client.close(); -} -function doStuffWithBranchServiceClient(client: BranchServiceClient) { - client.close(); -} -function doStuffWithCatalogServiceClient(client: CatalogServiceClient) { - client.close(); -} -function doStuffWithCompletionServiceClient(client: CompletionServiceClient) { - client.close(); -} -function doStuffWithControlServiceClient(client: ControlServiceClient) { - client.close(); -} -function doStuffWithConversationalSearchServiceClient(client: ConversationalSearchServiceClient) { - client.close(); -} -function doStuffWithGenerativeQuestionServiceClient(client: GenerativeQuestionServiceClient) { - client.close(); -} -function doStuffWithMerchantCenterAccountLinkServiceClient(client: MerchantCenterAccountLinkServiceClient) { - client.close(); -} -function doStuffWithModelServiceClient(client: ModelServiceClient) { - client.close(); -} -function doStuffWithPredictionServiceClient(client: PredictionServiceClient) { - client.close(); -} -function doStuffWithProductServiceClient(client: ProductServiceClient) { - client.close(); -} -function doStuffWithProjectServiceClient(client: ProjectServiceClient) { - client.close(); -} -function doStuffWithSearchServiceClient(client: SearchServiceClient) { - client.close(); -} -function doStuffWithServingConfigServiceClient(client: ServingConfigServiceClient) { - client.close(); -} -function doStuffWithUserEventServiceClient(client: UserEventServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const analyticsServiceClient = new AnalyticsServiceClient(); - doStuffWithAnalyticsServiceClient(analyticsServiceClient); - // check that the client instance can be created - const branchServiceClient = new BranchServiceClient(); - doStuffWithBranchServiceClient(branchServiceClient); - // check that the client instance can be created - const catalogServiceClient = new CatalogServiceClient(); - doStuffWithCatalogServiceClient(catalogServiceClient); - // check that the client instance can be created - const completionServiceClient = new CompletionServiceClient(); - doStuffWithCompletionServiceClient(completionServiceClient); - // check that the client instance can be created - const controlServiceClient = new ControlServiceClient(); - doStuffWithControlServiceClient(controlServiceClient); - // check that the client instance can be created - const conversationalSearchServiceClient = new ConversationalSearchServiceClient(); - doStuffWithConversationalSearchServiceClient(conversationalSearchServiceClient); - // check that the client instance can be created - const generativeQuestionServiceClient = new GenerativeQuestionServiceClient(); - doStuffWithGenerativeQuestionServiceClient(generativeQuestionServiceClient); - // check that the client instance can be created - const merchantCenterAccountLinkServiceClient = new MerchantCenterAccountLinkServiceClient(); - doStuffWithMerchantCenterAccountLinkServiceClient(merchantCenterAccountLinkServiceClient); - // check that the client instance can be created - const modelServiceClient = new ModelServiceClient(); - doStuffWithModelServiceClient(modelServiceClient); - // check that the client instance can be created - const predictionServiceClient = new PredictionServiceClient(); - doStuffWithPredictionServiceClient(predictionServiceClient); - // check that the client instance can be created - const productServiceClient = new ProductServiceClient(); - doStuffWithProductServiceClient(productServiceClient); - // check that the client instance can be created - const projectServiceClient = new ProjectServiceClient(); - doStuffWithProjectServiceClient(projectServiceClient); - // check that the client instance can be created - const searchServiceClient = new SearchServiceClient(); - doStuffWithSearchServiceClient(searchServiceClient); - // check that the client instance can be created - const servingConfigServiceClient = new ServingConfigServiceClient(); - doStuffWithServingConfigServiceClient(servingConfigServiceClient); - // check that the client instance can be created - const userEventServiceClient = new UserEventServiceClient(); - doStuffWithUserEventServiceClient(userEventServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_analytics_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_analytics_service_v2alpha.ts.baseline deleted file mode 100644 index 4e4320fcc73d..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_analytics_service_v2alpha.ts.baseline +++ /dev/null @@ -1,943 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as analyticsserviceModule from '../src'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.AnalyticsServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = analyticsserviceModule.v2alpha.AnalyticsServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = analyticsserviceModule.v2alpha.AnalyticsServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new analyticsserviceModule.v2alpha.AnalyticsServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = analyticsserviceModule.v2alpha.AnalyticsServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.analyticsServiceStub, undefined); - await client.initialize(); - assert(client.analyticsServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.analyticsServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.analyticsServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - 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); - }); - }); - - describe('exportAnalyticsMetrics', () => { - it('invokes exportAnalyticsMetrics without error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportAnalyticsMetrics = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportAnalyticsMetrics(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAnalyticsMetrics without error using callback', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportAnalyticsMetrics = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportAnalyticsMetrics( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAnalyticsMetrics with call error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportAnalyticsMetrics = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportAnalyticsMetrics(request), expectedError); - const actualRequest = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportAnalyticsMetrics with LRO error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportAnalyticsMetricsRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportAnalyticsMetrics = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportAnalyticsMetrics(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportAnalyticsMetrics as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportAnalyticsMetricsProgress without error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportAnalyticsMetricsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportAnalyticsMetricsProgress with error', async () => { - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportAnalyticsMetricsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new analyticsserviceModule.v2alpha.AnalyticsServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_branch_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_branch_service_v2alpha.ts.baseline deleted file mode 100644 index b2bbf1dd160a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_branch_service_v2alpha.ts.baseline +++ /dev/null @@ -1,993 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as branchserviceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v2alpha.BranchServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = branchserviceModule.v2alpha.BranchServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = branchserviceModule.v2alpha.BranchServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new branchserviceModule.v2alpha.BranchServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new branchserviceModule.v2alpha.BranchServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new branchserviceModule.v2alpha.BranchServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = branchserviceModule.v2alpha.BranchServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.branchServiceStub, undefined); - await client.initialize(); - assert(client.branchServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.branchServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.branchServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - 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); - }); - }); - - describe('listBranches', () => { - it('invokes listBranches without error', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListBranchesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesResponse() - ); - client.innerApiCalls.listBranches = stubSimpleCall(expectedResponse); - const [response] = await client.listBranches(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBranches without error using callback', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListBranchesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesResponse() - ); - client.innerApiCalls.listBranches = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBranches( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IListBranchesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBranches with error', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListBranchesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBranches = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBranches(request), expectedError); - const actualRequest = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBranches as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBranches with closed client', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListBranchesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListBranchesRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listBranches(request), expectedError); - }); - }); - - describe('getBranch', () => { - it('invokes getBranch without error', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetBranchRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Branch() - ); - client.innerApiCalls.getBranch = stubSimpleCall(expectedResponse); - const [response] = await client.getBranch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBranch without error using callback', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetBranchRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Branch() - ); - client.innerApiCalls.getBranch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBranch( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IBranch|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBranch with error', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetBranchRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBranch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBranch(request), expectedError); - const actualRequest = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBranch with closed client', async () => { - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetBranchRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBranch(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new branchserviceModule.v2alpha.BranchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_catalog_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_catalog_service_v2alpha.ts.baseline deleted file mode 100644 index c042b00f66e1..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_catalog_service_v2alpha.ts.baseline +++ /dev/null @@ -1,2307 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as catalogserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.CatalogServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = catalogserviceModule.v2alpha.CatalogServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = catalogserviceModule.v2alpha.CatalogServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new catalogserviceModule.v2alpha.CatalogServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = catalogserviceModule.v2alpha.CatalogServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.catalogServiceStub, undefined); - await client.initialize(); - assert(client.catalogServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.catalogServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.catalogServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - 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); - }); - }); - - describe('updateCatalog', () => { - it('invokes updateCatalog without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCatalogRequest() - ); - request.catalog ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCatalogRequest', ['catalog', 'name']); - request.catalog.name = defaultValue1; - const expectedHeaderRequestParams = `catalog.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Catalog() - ); - client.innerApiCalls.updateCatalog = stubSimpleCall(expectedResponse); - const [response] = await client.updateCatalog(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCatalog without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCatalogRequest() - ); - request.catalog ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCatalogRequest', ['catalog', 'name']); - request.catalog.name = defaultValue1; - const expectedHeaderRequestParams = `catalog.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Catalog() - ); - client.innerApiCalls.updateCatalog = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCatalog( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICatalog|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCatalog with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCatalogRequest() - ); - request.catalog ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCatalogRequest', ['catalog', 'name']); - request.catalog.name = defaultValue1; - const expectedHeaderRequestParams = `catalog.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCatalog = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCatalog(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCatalog as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCatalog with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCatalogRequest() - ); - request.catalog ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCatalogRequest', ['catalog', 'name']); - request.catalog.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCatalog(request), expectedError); - }); - }); - - describe('setDefaultBranch', () => { - it('invokes setDefaultBranch without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.setDefaultBranch = stubSimpleCall(expectedResponse); - const [response] = await client.setDefaultBranch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setDefaultBranch without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.setDefaultBranch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setDefaultBranch( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setDefaultBranch with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.setDefaultBranch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setDefaultBranch(request), expectedError); - const actualRequest = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setDefaultBranch with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.setDefaultBranch(request), expectedError); - }); - }); - - describe('getDefaultBranch', () => { - it('invokes getDefaultBranch without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchResponse() - ); - client.innerApiCalls.getDefaultBranch = stubSimpleCall(expectedResponse); - const [response] = await client.getDefaultBranch(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDefaultBranch without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchResponse() - ); - client.innerApiCalls.getDefaultBranch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getDefaultBranch( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IGetDefaultBranchResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDefaultBranch with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getDefaultBranch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getDefaultBranch(request), expectedError); - const actualRequest = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getDefaultBranch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getDefaultBranch with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetDefaultBranchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetDefaultBranchRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getDefaultBranch(request), expectedError); - }); - }); - - describe('getCompletionConfig', () => { - it('invokes getCompletionConfig without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetCompletionConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetCompletionConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompletionConfig() - ); - client.innerApiCalls.getCompletionConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getCompletionConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCompletionConfig without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetCompletionConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetCompletionConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompletionConfig() - ); - client.innerApiCalls.getCompletionConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getCompletionConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICompletionConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCompletionConfig with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetCompletionConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetCompletionConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getCompletionConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getCompletionConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getCompletionConfig with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetCompletionConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetCompletionConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getCompletionConfig(request), expectedError); - }); - }); - - describe('updateCompletionConfig', () => { - it('invokes updateCompletionConfig without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest() - ); - request.completionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest', ['completionConfig', 'name']); - request.completionConfig.name = defaultValue1; - const expectedHeaderRequestParams = `completion_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompletionConfig() - ); - client.innerApiCalls.updateCompletionConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateCompletionConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCompletionConfig without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest() - ); - request.completionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest', ['completionConfig', 'name']); - request.completionConfig.name = defaultValue1; - const expectedHeaderRequestParams = `completion_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompletionConfig() - ); - client.innerApiCalls.updateCompletionConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateCompletionConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICompletionConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCompletionConfig with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest() - ); - request.completionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest', ['completionConfig', 'name']); - request.completionConfig.name = defaultValue1; - const expectedHeaderRequestParams = `completion_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateCompletionConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateCompletionConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateCompletionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateCompletionConfig with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest() - ); - request.completionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateCompletionConfigRequest', ['completionConfig', 'name']); - request.completionConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateCompletionConfig(request), expectedError); - }); - }); - - describe('getAttributesConfig', () => { - it('invokes getAttributesConfig without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAttributesConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAttributesConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.getAttributesConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getAttributesConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAttributesConfig without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAttributesConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAttributesConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.getAttributesConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getAttributesConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAttributesConfig with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAttributesConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAttributesConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getAttributesConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getAttributesConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAttributesConfig with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAttributesConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAttributesConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getAttributesConfig(request), expectedError); - }); - }); - - describe('updateAttributesConfig', () => { - it('invokes updateAttributesConfig without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest() - ); - request.attributesConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest', ['attributesConfig', 'name']); - request.attributesConfig.name = defaultValue1; - const expectedHeaderRequestParams = `attributes_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.updateAttributesConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateAttributesConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAttributesConfig without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest() - ); - request.attributesConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest', ['attributesConfig', 'name']); - request.attributesConfig.name = defaultValue1; - const expectedHeaderRequestParams = `attributes_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.updateAttributesConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateAttributesConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAttributesConfig with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest() - ); - request.attributesConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest', ['attributesConfig', 'name']); - request.attributesConfig.name = defaultValue1; - const expectedHeaderRequestParams = `attributes_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateAttributesConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateAttributesConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAttributesConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAttributesConfig with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest() - ); - request.attributesConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAttributesConfigRequest', ['attributesConfig', 'name']); - request.attributesConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateAttributesConfig(request), expectedError); - }); - }); - - describe('addCatalogAttribute', () => { - it('invokes addCatalogAttribute without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.addCatalogAttribute = stubSimpleCall(expectedResponse); - const [response] = await client.addCatalogAttribute(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addCatalogAttribute without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.addCatalogAttribute = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addCatalogAttribute( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addCatalogAttribute with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addCatalogAttribute = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addCatalogAttribute(request), expectedError); - const actualRequest = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addCatalogAttribute with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addCatalogAttribute(request), expectedError); - }); - }); - - describe('removeCatalogAttribute', () => { - it('invokes removeCatalogAttribute without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.removeCatalogAttribute = stubSimpleCall(expectedResponse); - const [response] = await client.removeCatalogAttribute(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeCatalogAttribute without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.removeCatalogAttribute = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.removeCatalogAttribute( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeCatalogAttribute with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeCatalogAttribute = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.removeCatalogAttribute(request), expectedError); - const actualRequest = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeCatalogAttribute with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.removeCatalogAttribute(request), expectedError); - }); - }); - - describe('batchRemoveCatalogAttributes', () => { - it('invokes batchRemoveCatalogAttributes without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesResponse() - ); - client.innerApiCalls.batchRemoveCatalogAttributes = stubSimpleCall(expectedResponse); - const [response] = await client.batchRemoveCatalogAttributes(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchRemoveCatalogAttributes without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesResponse() - ); - client.innerApiCalls.batchRemoveCatalogAttributes = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchRemoveCatalogAttributes( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IBatchRemoveCatalogAttributesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchRemoveCatalogAttributes with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchRemoveCatalogAttributes = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.batchRemoveCatalogAttributes(request), expectedError); - const actualRequest = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchRemoveCatalogAttributes as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchRemoveCatalogAttributes with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchRemoveCatalogAttributesRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.batchRemoveCatalogAttributes(request), expectedError); - }); - }); - - describe('replaceCatalogAttribute', () => { - it('invokes replaceCatalogAttribute without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.replaceCatalogAttribute = stubSimpleCall(expectedResponse); - const [response] = await client.replaceCatalogAttribute(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes replaceCatalogAttribute without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AttributesConfig() - ); - client.innerApiCalls.replaceCatalogAttribute = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.replaceCatalogAttribute( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAttributesConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes replaceCatalogAttribute with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedHeaderRequestParams = `attributes_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.replaceCatalogAttribute = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.replaceCatalogAttribute(request), expectedError); - const actualRequest = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.replaceCatalogAttribute as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes replaceCatalogAttribute with closed client', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ReplaceCatalogAttributeRequest', ['attributesConfig']); - request.attributesConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.replaceCatalogAttribute(request), expectedError); - }); - }); - - describe('listCatalogs', () => { - it('invokes listCatalogs without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - ]; - client.innerApiCalls.listCatalogs = stubSimpleCall(expectedResponse); - const [response] = await client.listCatalogs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCatalogs without error using callback', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - ]; - client.innerApiCalls.listCatalogs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listCatalogs( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICatalog[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCatalogs with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listCatalogs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listCatalogs(request), expectedError); - const actualRequest = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listCatalogs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listCatalogsStream without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - ]; - client.descriptors.page.listCatalogs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listCatalogsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Catalog[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Catalog) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listCatalogs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCatalogs, request)); - assert( - (client.descriptors.page.listCatalogs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listCatalogsStream with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCatalogs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listCatalogsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Catalog[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Catalog) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listCatalogs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listCatalogs, request)); - assert( - (client.descriptors.page.listCatalogs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCatalogs without error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Catalog()), - ]; - client.descriptors.page.listCatalogs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.ICatalog[] = []; - const iterable = client.listCatalogsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listCatalogs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCatalogs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listCatalogs with error', async () => { - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListCatalogsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListCatalogsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listCatalogs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listCatalogsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.ICatalog[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listCatalogs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listCatalogs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('location', async () => { - const fakePath = "/rendered/path/location"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.locationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.locationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath("projectValue", "locationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new catalogserviceModule.v2alpha.CatalogServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_completion_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_completion_service_v2alpha.ts.baseline deleted file mode 100644 index edb151f19161..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_completion_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1055 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as completionserviceModule from '../src'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.CompletionServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = completionserviceModule.v2alpha.CompletionServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = completionserviceModule.v2alpha.CompletionServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new completionserviceModule.v2alpha.CompletionServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new completionserviceModule.v2alpha.CompletionServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = completionserviceModule.v2alpha.CompletionServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.completionServiceStub, undefined); - await client.initialize(); - assert(client.completionServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.completionServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.completionServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - 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); - }); - }); - - describe('completeQuery', () => { - it('invokes completeQuery without error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CompleteQueryRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryResponse() - ); - client.innerApiCalls.completeQuery = stubSimpleCall(expectedResponse); - const [response] = await client.completeQuery(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes completeQuery without error using callback', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CompleteQueryRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryResponse() - ); - client.innerApiCalls.completeQuery = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.completeQuery( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ICompleteQueryResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes completeQuery with error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CompleteQueryRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.completeQuery = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.completeQuery(request), expectedError); - const actualRequest = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.completeQuery as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes completeQuery with closed client', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CompleteQueryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CompleteQueryRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.completeQuery(request), expectedError); - }); - }); - - describe('importCompletionData', () => { - it('invokes importCompletionData without error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportCompletionDataRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportCompletionDataRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importCompletionData = stubLongRunningCall(expectedResponse); - const [operation] = await client.importCompletionData(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCompletionData without error using callback', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportCompletionDataRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportCompletionDataRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importCompletionData = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importCompletionData( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCompletionData with call error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportCompletionDataRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportCompletionDataRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importCompletionData = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.importCompletionData(request), expectedError); - const actualRequest = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importCompletionData with LRO error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportCompletionDataRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportCompletionDataRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importCompletionData = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.importCompletionData(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importCompletionData as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportCompletionDataProgress without error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportCompletionDataProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportCompletionDataProgress with error', async () => { - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkImportCompletionDataProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new completionserviceModule.v2alpha.CompletionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_control_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_control_service_v2alpha.ts.baseline deleted file mode 100644 index 6a4bf6b4b0ca..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_control_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1505 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as controlserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.ControlServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = controlserviceModule.v2alpha.ControlServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = controlserviceModule.v2alpha.ControlServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new controlserviceModule.v2alpha.ControlServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new controlserviceModule.v2alpha.ControlServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new controlserviceModule.v2alpha.ControlServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = controlserviceModule.v2alpha.ControlServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.controlServiceStub, undefined); - await client.initialize(); - assert(client.controlServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.controlServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.controlServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - 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); - }); - }); - - describe('createControl', () => { - it('invokes createControl without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateControlRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.createControl = stubSimpleCall(expectedResponse); - const [response] = await client.createControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createControl without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateControlRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.createControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IControl|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createControl with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateControlRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createControl(request), expectedError); - const actualRequest = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createControl with closed client', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateControlRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createControl(request), expectedError); - }); - }); - - describe('deleteControl', () => { - it('invokes deleteControl without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteControl = stubSimpleCall(expectedResponse); - const [response] = await client.deleteControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteControl without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteControl( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteControl with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteControl(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteControl with closed client', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteControlRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteControl(request), expectedError); - }); - }); - - describe('updateControl', () => { - it('invokes updateControl without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateControlRequest() - ); - request.control ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateControlRequest', ['control', 'name']); - request.control.name = defaultValue1; - const expectedHeaderRequestParams = `control.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.updateControl = stubSimpleCall(expectedResponse); - const [response] = await client.updateControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateControl without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateControlRequest() - ); - request.control ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateControlRequest', ['control', 'name']); - request.control.name = defaultValue1; - const expectedHeaderRequestParams = `control.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.updateControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IControl|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateControl with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateControlRequest() - ); - request.control ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateControlRequest', ['control', 'name']); - request.control.name = defaultValue1; - const expectedHeaderRequestParams = `control.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateControl(request), expectedError); - const actualRequest = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateControl with closed client', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateControlRequest() - ); - request.control ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateControlRequest', ['control', 'name']); - request.control.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateControl(request), expectedError); - }); - }); - - describe('getControl', () => { - it('invokes getControl without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.getControl = stubSimpleCall(expectedResponse); - const [response] = await client.getControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getControl without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Control() - ); - client.innerApiCalls.getControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IControl|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getControl with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetControlRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getControl(request), expectedError); - const actualRequest = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getControl with closed client', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetControlRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getControl(request), expectedError); - }); - }); - - describe('listControls', () => { - it('invokes listControls without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - ]; - client.innerApiCalls.listControls = stubSimpleCall(expectedResponse); - const [response] = await client.listControls(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listControls without error using callback', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - ]; - client.innerApiCalls.listControls = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listControls( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IControl[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listControls with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listControls = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listControls(request), expectedError); - const actualRequest = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listControls as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listControlsStream without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - ]; - client.descriptors.page.listControls.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listControlsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Control[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Control) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listControls.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listControls, request)); - assert( - (client.descriptors.page.listControls.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listControlsStream with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listControls.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listControlsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Control[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Control) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listControls.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listControls, request)); - assert( - (client.descriptors.page.listControls.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listControls without error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Control()), - ]; - client.descriptors.page.listControls.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.IControl[] = []; - const iterable = client.listControlsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listControls.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listControls.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listControls with error', async () => { - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListControlsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListControlsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listControls.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listControlsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.IControl[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listControls.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listControls.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new controlserviceModule.v2alpha.ControlServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_conversational_search_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_conversational_search_service_v2alpha.ts.baseline deleted file mode 100644 index 3723e2c2fbb0..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_conversational_search_service_v2alpha.ts.baseline +++ /dev/null @@ -1,923 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as conversationalsearchserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -describe('v2alpha.ConversationalSearchServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.conversationalSearchServiceStub, undefined); - await client.initialize(); - assert(client.conversationalSearchServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.conversationalSearchServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.conversationalSearchServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - 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); - }); - }); - - describe('conversationalSearch', () => { - it('invokes conversationalSearch without error', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ConversationalSearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchResponse() - ); - client.innerApiCalls.conversationalSearch = stubServerStreamingCall(expectedResponse); - const stream = client.conversationalSearch(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ConversationalSearchResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes conversationalSearch without error and gaxServerStreamingRetries enabled', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ConversationalSearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchResponse() - ); - client.innerApiCalls.conversationalSearch = stubServerStreamingCall(expectedResponse); - const stream = client.conversationalSearch(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ConversationalSearchResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes conversationalSearch with error', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ConversationalSearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.conversationalSearch = stubServerStreamingCall(undefined, expectedError); - const stream = client.conversationalSearch(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ConversationalSearchResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.conversationalSearch as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes conversationalSearch with closed client', async () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ConversationalSearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ConversationalSearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.conversationalSearch(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ConversationalSearchResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new conversationalsearchserviceModule.v2alpha.ConversationalSearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_generative_question_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_generative_question_service_v2alpha.ts.baseline deleted file mode 100644 index c3531333f6d6..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_generative_question_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1325 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as generativequestionserviceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v2alpha.GenerativeQuestionServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.generativeQuestionServiceStub, undefined); - await client.initialize(); - assert(client.generativeQuestionServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.generativeQuestionServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.generativeQuestionServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - 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); - }); - }); - - describe('updateGenerativeQuestionsFeatureConfig', () => { - it('invokes updateGenerativeQuestionsFeatureConfig without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest() - ); - request.generativeQuestionsFeatureConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest', ['generativeQuestionsFeatureConfig', 'catalog']); - request.generativeQuestionsFeatureConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_questions_feature_config.catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionsFeatureConfig() - ); - client.innerApiCalls.updateGenerativeQuestionsFeatureConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateGenerativeQuestionsFeatureConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionsFeatureConfig without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest() - ); - request.generativeQuestionsFeatureConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest', ['generativeQuestionsFeatureConfig', 'catalog']); - request.generativeQuestionsFeatureConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_questions_feature_config.catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionsFeatureConfig() - ); - client.innerApiCalls.updateGenerativeQuestionsFeatureConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateGenerativeQuestionsFeatureConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IGenerativeQuestionsFeatureConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionsFeatureConfig with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest() - ); - request.generativeQuestionsFeatureConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest', ['generativeQuestionsFeatureConfig', 'catalog']); - request.generativeQuestionsFeatureConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_questions_feature_config.catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateGenerativeQuestionsFeatureConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateGenerativeQuestionsFeatureConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionsFeatureConfig with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest() - ); - request.generativeQuestionsFeatureConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionsFeatureConfigRequest', ['generativeQuestionsFeatureConfig', 'catalog']); - request.generativeQuestionsFeatureConfig.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateGenerativeQuestionsFeatureConfig(request), expectedError); - }); - }); - - describe('getGenerativeQuestionsFeatureConfig', () => { - it('invokes getGenerativeQuestionsFeatureConfig without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionsFeatureConfig() - ); - client.innerApiCalls.getGenerativeQuestionsFeatureConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getGenerativeQuestionsFeatureConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGenerativeQuestionsFeatureConfig without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionsFeatureConfig() - ); - client.innerApiCalls.getGenerativeQuestionsFeatureConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getGenerativeQuestionsFeatureConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IGenerativeQuestionsFeatureConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGenerativeQuestionsFeatureConfig with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedHeaderRequestParams = `catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getGenerativeQuestionsFeatureConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getGenerativeQuestionsFeatureConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGenerativeQuestionsFeatureConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGenerativeQuestionsFeatureConfig with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetGenerativeQuestionsFeatureConfigRequest', ['catalog']); - request.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getGenerativeQuestionsFeatureConfig(request), expectedError); - }); - }); - - describe('listGenerativeQuestionConfigs', () => { - it('invokes listGenerativeQuestionConfigs without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsResponse() - ); - client.innerApiCalls.listGenerativeQuestionConfigs = stubSimpleCall(expectedResponse); - const [response] = await client.listGenerativeQuestionConfigs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGenerativeQuestionConfigs without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsResponse() - ); - client.innerApiCalls.listGenerativeQuestionConfigs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listGenerativeQuestionConfigs( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IListGenerativeQuestionConfigsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGenerativeQuestionConfigs with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listGenerativeQuestionConfigs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listGenerativeQuestionConfigs(request), expectedError); - const actualRequest = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGenerativeQuestionConfigs with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listGenerativeQuestionConfigs(request), expectedError); - }); - }); - - describe('updateGenerativeQuestionConfig', () => { - it('invokes updateGenerativeQuestionConfig without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest() - ); - request.generativeQuestionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest', ['generativeQuestionConfig', 'catalog']); - request.generativeQuestionConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_question_config.catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionConfig() - ); - client.innerApiCalls.updateGenerativeQuestionConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateGenerativeQuestionConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionConfig without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest() - ); - request.generativeQuestionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest', ['generativeQuestionConfig', 'catalog']); - request.generativeQuestionConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_question_config.catalog=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GenerativeQuestionConfig() - ); - client.innerApiCalls.updateGenerativeQuestionConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateGenerativeQuestionConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IGenerativeQuestionConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionConfig with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest() - ); - request.generativeQuestionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest', ['generativeQuestionConfig', 'catalog']); - request.generativeQuestionConfig.catalog = defaultValue1; - const expectedHeaderRequestParams = `generative_question_config.catalog=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateGenerativeQuestionConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateGenerativeQuestionConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateGenerativeQuestionConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateGenerativeQuestionConfig with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest() - ); - request.generativeQuestionConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateGenerativeQuestionConfigRequest', ['generativeQuestionConfig', 'catalog']); - request.generativeQuestionConfig.catalog = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateGenerativeQuestionConfig(request), expectedError); - }); - }); - - describe('batchUpdateGenerativeQuestionConfigs', () => { - it('invokes batchUpdateGenerativeQuestionConfigs without error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsResponse() - ); - client.innerApiCalls.batchUpdateGenerativeQuestionConfigs = stubSimpleCall(expectedResponse); - const [response] = await client.batchUpdateGenerativeQuestionConfigs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchUpdateGenerativeQuestionConfigs without error using callback', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsResponse() - ); - client.innerApiCalls.batchUpdateGenerativeQuestionConfigs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchUpdateGenerativeQuestionConfigs( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IBatchUpdateGenerativeQuestionConfigsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchUpdateGenerativeQuestionConfigs with error', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchUpdateGenerativeQuestionConfigs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.batchUpdateGenerativeQuestionConfigs(request), expectedError); - const actualRequest = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchUpdateGenerativeQuestionConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchUpdateGenerativeQuestionConfigs with closed client', async () => { - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.BatchUpdateGenerativeQuestionConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.batchUpdateGenerativeQuestionConfigs(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new generativequestionserviceModule.v2alpha.GenerativeQuestionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_merchant_center_account_link_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_merchant_center_account_link_service_v2alpha.ts.baseline deleted file mode 100644 index b8166ae516d3..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_merchant_center_account_link_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1163 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as merchantcenteraccountlinkserviceModule from '../src'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.MerchantCenterAccountLinkServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.merchantCenterAccountLinkServiceStub, undefined); - await client.initialize(); - assert(client.merchantCenterAccountLinkServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.merchantCenterAccountLinkServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.merchantCenterAccountLinkServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - 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); - }); - }); - - describe('listMerchantCenterAccountLinks', () => { - it('invokes listMerchantCenterAccountLinks without error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksResponse() - ); - client.innerApiCalls.listMerchantCenterAccountLinks = stubSimpleCall(expectedResponse); - const [response] = await client.listMerchantCenterAccountLinks(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMerchantCenterAccountLinks without error using callback', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksResponse() - ); - client.innerApiCalls.listMerchantCenterAccountLinks = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listMerchantCenterAccountLinks( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IListMerchantCenterAccountLinksResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMerchantCenterAccountLinks with error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listMerchantCenterAccountLinks = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listMerchantCenterAccountLinks(request), expectedError); - const actualRequest = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listMerchantCenterAccountLinks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listMerchantCenterAccountLinks with closed client', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListMerchantCenterAccountLinksRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listMerchantCenterAccountLinks(request), expectedError); - }); - }); - - describe('deleteMerchantCenterAccountLink', () => { - it('invokes deleteMerchantCenterAccountLink without error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteMerchantCenterAccountLink = stubSimpleCall(expectedResponse); - const [response] = await client.deleteMerchantCenterAccountLink(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMerchantCenterAccountLink without error using callback', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteMerchantCenterAccountLink = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteMerchantCenterAccountLink( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMerchantCenterAccountLink with error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteMerchantCenterAccountLink = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteMerchantCenterAccountLink(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteMerchantCenterAccountLink with closed client', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteMerchantCenterAccountLinkRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteMerchantCenterAccountLink(request), expectedError); - }); - }); - - describe('createMerchantCenterAccountLink', () => { - it('invokes createMerchantCenterAccountLink without error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createMerchantCenterAccountLink = stubLongRunningCall(expectedResponse); - const [operation] = await client.createMerchantCenterAccountLink(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMerchantCenterAccountLink without error using callback', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createMerchantCenterAccountLink = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createMerchantCenterAccountLink( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMerchantCenterAccountLink with call error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createMerchantCenterAccountLink = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.createMerchantCenterAccountLink(request), expectedError); - const actualRequest = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createMerchantCenterAccountLink with LRO error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateMerchantCenterAccountLinkRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createMerchantCenterAccountLink = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.createMerchantCenterAccountLink(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createMerchantCenterAccountLink as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateMerchantCenterAccountLinkProgress without error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateMerchantCenterAccountLinkProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateMerchantCenterAccountLinkProgress with error', async () => { - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCreateMerchantCenterAccountLinkProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new merchantcenteraccountlinkserviceModule.v2alpha.MerchantCenterAccountLinkServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_model_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_model_service_v2alpha.ts.baseline deleted file mode 100644 index 36022a799068..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_model_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1937 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as modelserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.ModelServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = modelserviceModule.v2alpha.ModelServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = modelserviceModule.v2alpha.ModelServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new modelserviceModule.v2alpha.ModelServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new modelserviceModule.v2alpha.ModelServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new modelserviceModule.v2alpha.ModelServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = modelserviceModule.v2alpha.ModelServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.modelServiceStub, undefined); - await client.initialize(); - assert(client.modelServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.modelServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.modelServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - 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); - }); - }); - - describe('getModel', () => { - it('invokes getModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.getModel = stubSimpleCall(expectedResponse); - const [response] = await client.getModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.getModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getModel( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getModel(request), expectedError); - const actualRequest = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetModelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getModel(request), expectedError); - }); - }); - - describe('pauseModel', () => { - it('invokes pauseModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PauseModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PauseModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.pauseModel = stubSimpleCall(expectedResponse); - const [response] = await client.pauseModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PauseModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PauseModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.pauseModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pauseModel( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PauseModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PauseModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.pauseModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pauseModel(request), expectedError); - const actualRequest = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PauseModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PauseModelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pauseModel(request), expectedError); - }); - }); - - describe('resumeModel', () => { - it('invokes resumeModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ResumeModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ResumeModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.resumeModel = stubSimpleCall(expectedResponse); - const [response] = await client.resumeModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ResumeModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ResumeModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.resumeModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resumeModel( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ResumeModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ResumeModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.resumeModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.resumeModel(request), expectedError); - const actualRequest = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ResumeModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ResumeModelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.resumeModel(request), expectedError); - }); - }); - - describe('deleteModel', () => { - it('invokes deleteModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteModel = stubSimpleCall(expectedResponse); - const [response] = await client.deleteModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteModel( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteModel(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteModelRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteModel(request), expectedError); - }); - }); - - describe('updateModel', () => { - it('invokes updateModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateModelRequest() - ); - request.model ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateModelRequest', ['model', 'name']); - request.model.name = defaultValue1; - const expectedHeaderRequestParams = `model.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.updateModel = stubSimpleCall(expectedResponse); - const [response] = await client.updateModel(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateModelRequest() - ); - request.model ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateModelRequest', ['model', 'name']); - request.model.name = defaultValue1; - const expectedHeaderRequestParams = `model.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Model() - ); - client.innerApiCalls.updateModel = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateModel( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateModel with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateModelRequest() - ); - request.model ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateModelRequest', ['model', 'name']); - request.model.name = defaultValue1; - const expectedHeaderRequestParams = `model.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateModel = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateModel(request), expectedError); - const actualRequest = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateModel with closed client', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateModelRequest() - ); - request.model ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateModelRequest', ['model', 'name']); - request.model.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateModel(request), expectedError); - }); - }); - - describe('createModel', () => { - it('invokes createModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateModelRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createModel = stubLongRunningCall(expectedResponse); - const [operation] = await client.createModel(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateModelRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createModel = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createModel( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createModel with call error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateModelRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createModel = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.createModel(request), expectedError); - const actualRequest = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createModel with LRO error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateModelRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createModel = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.createModel(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateModelProgress without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateModelProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateModelProgress with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCreateModelProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('tuneModel', () => { - it('invokes tuneModel without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.TuneModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.TuneModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.tuneModel = stubLongRunningCall(expectedResponse); - const [operation] = await client.tuneModel(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes tuneModel without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.TuneModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.TuneModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.tuneModel = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.tuneModel( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes tuneModel with call error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.TuneModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.TuneModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.tuneModel = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.tuneModel(request), expectedError); - const actualRequest = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes tuneModel with LRO error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.TuneModelRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.TuneModelRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.tuneModel = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.tuneModel(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.tuneModel as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkTuneModelProgress without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkTuneModelProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkTuneModelProgress with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkTuneModelProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listModels', () => { - it('invokes listModels without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - ]; - client.innerApiCalls.listModels = stubSimpleCall(expectedResponse); - const [response] = await client.listModels(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModels without error using callback', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - ]; - client.innerApiCalls.listModels = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listModels( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IModel[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModels with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listModels = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listModels(request), expectedError); - const actualRequest = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listModels as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listModelsStream without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - ]; - client.descriptors.page.listModels.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listModelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Model[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Model) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listModels, request)); - assert( - (client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listModelsStream with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listModels.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listModelsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Model[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Model) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listModels, request)); - assert( - (client.descriptors.page.listModels.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listModels without error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Model()), - ]; - client.descriptors.page.listModels.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.IModel[] = []; - const iterable = client.listModelsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listModels with error', async () => { - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListModelsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListModelsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listModels.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listModelsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.IModel[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listModels.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new modelserviceModule.v2alpha.ModelServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_prediction_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_prediction_service_v2alpha.ts.baseline deleted file mode 100644 index 35230e3a276a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_prediction_service_v2alpha.ts.baseline +++ /dev/null @@ -1,885 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as predictionserviceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v2alpha.PredictionServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = predictionserviceModule.v2alpha.PredictionServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = predictionserviceModule.v2alpha.PredictionServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new predictionserviceModule.v2alpha.PredictionServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = predictionserviceModule.v2alpha.PredictionServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.predictionServiceStub, undefined); - await client.initialize(); - assert(client.predictionServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.predictionServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.predictionServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - 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); - }); - }); - - describe('predict', () => { - it('invokes predict without error', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PredictRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictResponse() - ); - client.innerApiCalls.predict = stubSimpleCall(expectedResponse); - const [response] = await client.predict(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes predict without error using callback', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PredictRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictResponse() - ); - client.innerApiCalls.predict = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.predict( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IPredictResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes predict with error', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PredictRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.predict = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.predict(request), expectedError); - const actualRequest = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.predict as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes predict with closed client', async () => { - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PredictRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PredictRequest', ['placement']); - request.placement = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.predict(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new predictionserviceModule.v2alpha.PredictionServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_product_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_product_service_v2alpha.ts.baseline deleted file mode 100644 index d806c5a092c6..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_product_service_v2alpha.ts.baseline +++ /dev/null @@ -1,2757 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as productserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.ProductServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = productserviceModule.v2alpha.ProductServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = productserviceModule.v2alpha.ProductServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new productserviceModule.v2alpha.ProductServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new productserviceModule.v2alpha.ProductServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new productserviceModule.v2alpha.ProductServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = productserviceModule.v2alpha.ProductServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.productServiceStub, undefined); - await client.initialize(); - assert(client.productServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.productServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.productServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - 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); - }); - }); - - describe('createProduct', () => { - it('invokes createProduct without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateProductRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.createProduct = stubSimpleCall(expectedResponse); - const [response] = await client.createProduct(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createProduct without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateProductRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.createProduct = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createProduct( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProduct|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createProduct with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateProductRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createProduct = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createProduct(request), expectedError); - const actualRequest = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createProduct with closed client', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateProductRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createProduct(request), expectedError); - }); - }); - - describe('getProduct', () => { - it('invokes getProduct without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.getProduct = stubSimpleCall(expectedResponse); - const [response] = await client.getProduct(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProduct without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.getProduct = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getProduct( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProduct|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProduct with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getProduct = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getProduct(request), expectedError); - const actualRequest = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProduct with closed client', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProductRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getProduct(request), expectedError); - }); - }); - - describe('updateProduct', () => { - it('invokes updateProduct without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateProductRequest() - ); - request.product ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateProductRequest', ['product', 'name']); - request.product.name = defaultValue1; - const expectedHeaderRequestParams = `product.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.updateProduct = stubSimpleCall(expectedResponse); - const [response] = await client.updateProduct(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProduct without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateProductRequest() - ); - request.product ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateProductRequest', ['product', 'name']); - request.product.name = defaultValue1; - const expectedHeaderRequestParams = `product.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Product() - ); - client.innerApiCalls.updateProduct = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateProduct( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProduct|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProduct with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateProductRequest() - ); - request.product ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateProductRequest', ['product', 'name']); - request.product.name = defaultValue1; - const expectedHeaderRequestParams = `product.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateProduct = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateProduct(request), expectedError); - const actualRequest = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateProduct with closed client', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateProductRequest() - ); - request.product ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateProductRequest', ['product', 'name']); - request.product.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateProduct(request), expectedError); - }); - }); - - describe('deleteProduct', () => { - it('invokes deleteProduct without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteProduct = stubSimpleCall(expectedResponse); - const [response] = await client.deleteProduct(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteProduct without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteProduct = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteProduct( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteProduct with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteProductRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteProduct = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteProduct(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteProduct as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteProduct with closed client', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteProductRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteProductRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteProduct(request), expectedError); - }); - }); - - describe('purgeProducts', () => { - it('invokes purgeProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.purgeProducts = stubLongRunningCall(expectedResponse); - const [operation] = await client.purgeProducts(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeProducts without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.purgeProducts = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.purgeProducts( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeProducts with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeProducts = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.purgeProducts(request), expectedError); - const actualRequest = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeProducts with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeProducts = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.purgeProducts(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkPurgeProductsProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkPurgeProductsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkPurgeProductsProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkPurgeProductsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('importProducts', () => { - it('invokes importProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importProducts = stubLongRunningCall(expectedResponse); - const [operation] = await client.importProducts(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importProducts without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importProducts = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importProducts( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importProducts with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importProducts = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.importProducts(request), expectedError); - const actualRequest = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importProducts with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importProducts = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.importProducts(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportProductsProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportProductsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportProductsProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkImportProductsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('exportProducts', () => { - it('invokes exportProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportProducts = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportProducts(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportProducts without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportProducts = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportProducts( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportProducts with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportProducts = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportProducts(request), expectedError); - const actualRequest = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportProducts with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportProducts = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportProducts(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportProductsProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportProductsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportProductsProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportProductsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('setInventory', () => { - it('invokes setInventory without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetInventoryRequest() - ); - request.inventory ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetInventoryRequest', ['inventory', 'name']); - request.inventory.name = defaultValue1; - const expectedHeaderRequestParams = `inventory.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.setInventory = stubLongRunningCall(expectedResponse); - const [operation] = await client.setInventory(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setInventory without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetInventoryRequest() - ); - request.inventory ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetInventoryRequest', ['inventory', 'name']); - request.inventory.name = defaultValue1; - const expectedHeaderRequestParams = `inventory.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.setInventory = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setInventory( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setInventory with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetInventoryRequest() - ); - request.inventory ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetInventoryRequest', ['inventory', 'name']); - request.inventory.name = defaultValue1; - const expectedHeaderRequestParams = `inventory.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.setInventory = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.setInventory(request), expectedError); - const actualRequest = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setInventory with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SetInventoryRequest() - ); - request.inventory ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SetInventoryRequest', ['inventory', 'name']); - request.inventory.name = defaultValue1; - const expectedHeaderRequestParams = `inventory.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.setInventory = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.setInventory(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setInventory as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkSetInventoryProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkSetInventoryProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkSetInventoryProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkSetInventoryProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('addFulfillmentPlaces', () => { - it('invokes addFulfillmentPlaces without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.addFulfillmentPlaces = stubLongRunningCall(expectedResponse); - const [operation] = await client.addFulfillmentPlaces(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addFulfillmentPlaces without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.addFulfillmentPlaces = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addFulfillmentPlaces( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addFulfillmentPlaces with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addFulfillmentPlaces = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.addFulfillmentPlaces(request), expectedError); - const actualRequest = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addFulfillmentPlaces with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addFulfillmentPlaces = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.addFulfillmentPlaces(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkAddFulfillmentPlacesProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkAddFulfillmentPlacesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkAddFulfillmentPlacesProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkAddFulfillmentPlacesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('removeFulfillmentPlaces', () => { - it('invokes removeFulfillmentPlaces without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.removeFulfillmentPlaces = stubLongRunningCall(expectedResponse); - const [operation] = await client.removeFulfillmentPlaces(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeFulfillmentPlaces without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.removeFulfillmentPlaces = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.removeFulfillmentPlaces( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeFulfillmentPlaces with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeFulfillmentPlaces = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.removeFulfillmentPlaces(request), expectedError); - const actualRequest = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeFulfillmentPlaces with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveFulfillmentPlacesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeFulfillmentPlaces = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.removeFulfillmentPlaces(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeFulfillmentPlaces as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkRemoveFulfillmentPlacesProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkRemoveFulfillmentPlacesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkRemoveFulfillmentPlacesProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkRemoveFulfillmentPlacesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('addLocalInventories', () => { - it('invokes addLocalInventories without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.addLocalInventories = stubLongRunningCall(expectedResponse); - const [operation] = await client.addLocalInventories(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addLocalInventories without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.addLocalInventories = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addLocalInventories( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addLocalInventories with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addLocalInventories = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.addLocalInventories(request), expectedError); - const actualRequest = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addLocalInventories with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addLocalInventories = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.addLocalInventories(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkAddLocalInventoriesProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkAddLocalInventoriesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkAddLocalInventoriesProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkAddLocalInventoriesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('removeLocalInventories', () => { - it('invokes removeLocalInventories without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.removeLocalInventories = stubLongRunningCall(expectedResponse); - const [operation] = await client.removeLocalInventories(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeLocalInventories without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.removeLocalInventories = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.removeLocalInventories( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeLocalInventories with call error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeLocalInventories = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.removeLocalInventories(request), expectedError); - const actualRequest = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeLocalInventories with LRO error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveLocalInventoriesRequest', ['product']); - request.product = defaultValue1; - const expectedHeaderRequestParams = `product=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeLocalInventories = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.removeLocalInventories(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeLocalInventories as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkRemoveLocalInventoriesProgress without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkRemoveLocalInventoriesProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkRemoveLocalInventoriesProgress with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkRemoveLocalInventoriesProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listProducts', () => { - it('invokes listProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - ]; - client.innerApiCalls.listProducts = stubSimpleCall(expectedResponse); - const [response] = await client.listProducts(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProducts without error using callback', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - ]; - client.innerApiCalls.listProducts = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listProducts( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProduct[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProducts with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listProducts = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listProducts(request), expectedError); - const actualRequest = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listProducts as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listProductsStream without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - ]; - client.descriptors.page.listProducts.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listProductsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Product[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Product) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listProducts.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listProducts, request)); - assert( - (client.descriptors.page.listProducts.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listProductsStream with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listProducts.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listProductsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.Product[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.Product) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listProducts.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listProducts, request)); - assert( - (client.descriptors.page.listProducts.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listProducts without error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.Product()), - ]; - client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.IProduct[] = []; - const iterable = client.listProductsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listProducts.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listProducts.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listProducts with error', async () => { - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListProductsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListProductsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listProducts.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listProductsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.IProduct[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listProducts.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listProducts.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new productserviceModule.v2alpha.ProductServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_project_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_project_service_v2alpha.ts.baseline deleted file mode 100644 index a0d3cc3643ef..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_project_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1741 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as projectserviceModule from '../src'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.ProjectServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = projectserviceModule.v2alpha.ProjectServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = projectserviceModule.v2alpha.ProjectServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new projectserviceModule.v2alpha.ProjectServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new projectserviceModule.v2alpha.ProjectServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = projectserviceModule.v2alpha.ProjectServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.projectServiceStub, undefined); - await client.initialize(); - assert(client.projectServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.projectServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.projectServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - 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); - }); - }); - - describe('getProject', () => { - it('invokes getProject without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProjectRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProjectRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Project() - ); - client.innerApiCalls.getProject = stubSimpleCall(expectedResponse); - const [response] = await client.getProject(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProject without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProjectRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProjectRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Project() - ); - client.innerApiCalls.getProject = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getProject( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProject|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProject with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProjectRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProjectRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getProject = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getProject(request), expectedError); - const actualRequest = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getProject as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getProject with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetProjectRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetProjectRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getProject(request), expectedError); - }); - }); - - describe('acceptTerms', () => { - it('invokes acceptTerms without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AcceptTermsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AcceptTermsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Project() - ); - client.innerApiCalls.acceptTerms = stubSimpleCall(expectedResponse); - const [response] = await client.acceptTerms(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acceptTerms without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AcceptTermsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AcceptTermsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.Project() - ); - client.innerApiCalls.acceptTerms = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.acceptTerms( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IProject|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acceptTerms with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AcceptTermsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AcceptTermsRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.acceptTerms = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.acceptTerms(request), expectedError); - const actualRequest = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.acceptTerms as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes acceptTerms with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AcceptTermsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AcceptTermsRequest', ['project']); - request.project = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.acceptTerms(request), expectedError); - }); - }); - - describe('listEnrolledSolutions', () => { - it('invokes listEnrolledSolutions without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsResponse() - ); - client.innerApiCalls.listEnrolledSolutions = stubSimpleCall(expectedResponse); - const [response] = await client.listEnrolledSolutions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEnrolledSolutions without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsResponse() - ); - client.innerApiCalls.listEnrolledSolutions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listEnrolledSolutions( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IListEnrolledSolutionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEnrolledSolutions with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listEnrolledSolutions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listEnrolledSolutions(request), expectedError); - const actualRequest = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listEnrolledSolutions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listEnrolledSolutions with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListEnrolledSolutionsRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listEnrolledSolutions(request), expectedError); - }); - }); - - describe('getLoggingConfig', () => { - it('invokes getLoggingConfig without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetLoggingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetLoggingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.LoggingConfig() - ); - client.innerApiCalls.getLoggingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getLoggingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLoggingConfig without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetLoggingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetLoggingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.LoggingConfig() - ); - client.innerApiCalls.getLoggingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getLoggingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ILoggingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLoggingConfig with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetLoggingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetLoggingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getLoggingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getLoggingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getLoggingConfig with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetLoggingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetLoggingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getLoggingConfig(request), expectedError); - }); - }); - - describe('updateLoggingConfig', () => { - it('invokes updateLoggingConfig without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest() - ); - request.loggingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest', ['loggingConfig', 'name']); - request.loggingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `logging_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.LoggingConfig() - ); - client.innerApiCalls.updateLoggingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateLoggingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLoggingConfig without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest() - ); - request.loggingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest', ['loggingConfig', 'name']); - request.loggingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `logging_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.LoggingConfig() - ); - client.innerApiCalls.updateLoggingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateLoggingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.ILoggingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLoggingConfig with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest() - ); - request.loggingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest', ['loggingConfig', 'name']); - request.loggingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `logging_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateLoggingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateLoggingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateLoggingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateLoggingConfig with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest() - ); - request.loggingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateLoggingConfigRequest', ['loggingConfig', 'name']); - request.loggingConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateLoggingConfig(request), expectedError); - }); - }); - - describe('getAlertConfig', () => { - it('invokes getAlertConfig without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAlertConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAlertConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AlertConfig() - ); - client.innerApiCalls.getAlertConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getAlertConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertConfig without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAlertConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAlertConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AlertConfig() - ); - client.innerApiCalls.getAlertConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getAlertConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAlertConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertConfig with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAlertConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAlertConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getAlertConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getAlertConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getAlertConfig with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetAlertConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetAlertConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getAlertConfig(request), expectedError); - }); - }); - - describe('updateAlertConfig', () => { - it('invokes updateAlertConfig without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAlertConfigRequest() - ); - request.alertConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAlertConfigRequest', ['alertConfig', 'name']); - request.alertConfig.name = defaultValue1; - const expectedHeaderRequestParams = `alert_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AlertConfig() - ); - client.innerApiCalls.updateAlertConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateAlertConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertConfig without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAlertConfigRequest() - ); - request.alertConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAlertConfigRequest', ['alertConfig', 'name']); - request.alertConfig.name = defaultValue1; - const expectedHeaderRequestParams = `alert_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AlertConfig() - ); - client.innerApiCalls.updateAlertConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateAlertConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IAlertConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertConfig with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAlertConfigRequest() - ); - request.alertConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAlertConfigRequest', ['alertConfig', 'name']); - request.alertConfig.name = defaultValue1; - const expectedHeaderRequestParams = `alert_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateAlertConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateAlertConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateAlertConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateAlertConfig with closed client', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateAlertConfigRequest() - ); - request.alertConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateAlertConfigRequest', ['alertConfig', 'name']); - request.alertConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateAlertConfig(request), expectedError); - }); - }); - - describe('enrollSolution', () => { - it('invokes enrollSolution without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.EnrollSolutionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.EnrollSolutionRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.enrollSolution = stubLongRunningCall(expectedResponse); - const [operation] = await client.enrollSolution(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enrollSolution without error using callback', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.EnrollSolutionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.EnrollSolutionRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.enrollSolution = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.enrollSolution( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enrollSolution with call error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.EnrollSolutionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.EnrollSolutionRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.enrollSolution = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.enrollSolution(request), expectedError); - const actualRequest = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes enrollSolution with LRO error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.EnrollSolutionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.EnrollSolutionRequest', ['project']); - request.project = defaultValue1; - const expectedHeaderRequestParams = `project=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.enrollSolution = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.enrollSolution(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.enrollSolution as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkEnrollSolutionProgress without error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkEnrollSolutionProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkEnrollSolutionProgress with error', async () => { - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkEnrollSolutionProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', async () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new projectserviceModule.v2alpha.ProjectServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_search_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_search_service_v2alpha.ts.baseline deleted file mode 100644 index 66e39d3fa6ca..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_search_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1123 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as searchserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.SearchServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = searchserviceModule.v2alpha.SearchServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = searchserviceModule.v2alpha.SearchServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new searchserviceModule.v2alpha.SearchServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new searchserviceModule.v2alpha.SearchServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new searchserviceModule.v2alpha.SearchServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = searchserviceModule.v2alpha.SearchServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.searchServiceStub, undefined); - await client.initialize(); - assert(client.searchServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.searchServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.searchServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - 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); - }); - }); - - describe('search', () => { - it('invokes search without error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - ]; - client.innerApiCalls.search = stubSimpleCall(expectedResponse); - const [response] = await client.search(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes search without error using callback', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - ]; - client.innerApiCalls.search = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.search( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.SearchResponse.ISearchResult[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes search with error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.search = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.search(request), expectedError); - const actualRequest = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.search as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchStream without error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - ]; - client.descriptors.page.search.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.searchStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.search.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.search, request)); - assert( - (client.descriptors.page.search.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes searchStream with error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.search.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.searchStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.search.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.search, request)); - assert( - (client.descriptors.page.search.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with search without error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.SearchResponse.SearchResult()), - ]; - client.descriptors.page.search.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.SearchResponse.ISearchResult[] = []; - const iterable = client.searchAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.search.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.search.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with search with error', async () => { - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.SearchRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.SearchRequest', ['placement']); - request.placement = defaultValue1; - const expectedHeaderRequestParams = `placement=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.search.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.searchAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.SearchResponse.ISearchResult[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.search.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.search.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('experiment', async () => { - const fakePath = "/rendered/path/experiment"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - experiment: "experimentValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.experimentPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.experimentPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('experimentPath', () => { - const result = client.experimentPath("projectValue", "locationValue", "catalogValue", "experimentValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.experimentPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromExperimentName', () => { - const result = client.matchProjectFromExperimentName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.experimentPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromExperimentName', () => { - const result = client.matchLocationFromExperimentName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.experimentPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromExperimentName', () => { - const result = client.matchCatalogFromExperimentName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.experimentPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchExperimentFromExperimentName', () => { - const result = client.matchExperimentFromExperimentName(fakePath); - assert.strictEqual(result, "experimentValue"); - assert((client.pathTemplates.experimentPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new searchserviceModule.v2alpha.SearchServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_serving_config_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_serving_config_service_v2alpha.ts.baseline deleted file mode 100644 index 1638a554681a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_serving_config_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1721 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as servingconfigserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2alpha.ServingConfigServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = servingconfigserviceModule.v2alpha.ServingConfigServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = servingconfigserviceModule.v2alpha.ServingConfigServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = servingconfigserviceModule.v2alpha.ServingConfigServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.servingConfigServiceStub, undefined); - await client.initialize(); - assert(client.servingConfigServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.servingConfigServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.servingConfigServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - 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); - }); - }); - - describe('createServingConfig', () => { - it('invokes createServingConfig without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateServingConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.createServingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.createServingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServingConfig without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateServingConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.createServingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createServingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServingConfig with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateServingConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createServingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createServingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createServingConfig with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CreateServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CreateServingConfigRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createServingConfig(request), expectedError); - }); - }); - - describe('deleteServingConfig', () => { - it('invokes deleteServingConfig without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteServingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.deleteServingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServingConfig without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteServingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteServingConfig( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServingConfig with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteServingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteServingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteServingConfig with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.DeleteServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.DeleteServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteServingConfig(request), expectedError); - }); - }); - - describe('updateServingConfig', () => { - it('invokes updateServingConfig without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateServingConfigRequest() - ); - request.servingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateServingConfigRequest', ['servingConfig', 'name']); - request.servingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `serving_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.updateServingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.updateServingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServingConfig without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateServingConfigRequest() - ); - request.servingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateServingConfigRequest', ['servingConfig', 'name']); - request.servingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `serving_config.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.updateServingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateServingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServingConfig with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateServingConfigRequest() - ); - request.servingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateServingConfigRequest', ['servingConfig', 'name']); - request.servingConfig.name = defaultValue1; - const expectedHeaderRequestParams = `serving_config.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateServingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateServingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateServingConfig with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UpdateServingConfigRequest() - ); - request.servingConfig ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.UpdateServingConfigRequest', ['servingConfig', 'name']); - request.servingConfig.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateServingConfig(request), expectedError); - }); - }); - - describe('getServingConfig', () => { - it('invokes getServingConfig without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.getServingConfig = stubSimpleCall(expectedResponse); - const [response] = await client.getServingConfig(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServingConfig without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.getServingConfig = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getServingConfig( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServingConfig with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getServingConfig = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getServingConfig(request), expectedError); - const actualRequest = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getServingConfig as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getServingConfig with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.GetServingConfigRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.GetServingConfigRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getServingConfig(request), expectedError); - }); - }); - - describe('addControl', () => { - it('invokes addControl without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.addControl = stubSimpleCall(expectedResponse); - const [response] = await client.addControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addControl without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.addControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.addControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addControl with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.addControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.addControl(request), expectedError); - const actualRequest = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.addControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes addControl with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.AddControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.AddControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.addControl(request), expectedError); - }); - }); - - describe('removeControl', () => { - it('invokes removeControl without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.removeControl = stubSimpleCall(expectedResponse); - const [response] = await client.removeControl(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeControl without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ServingConfig() - ); - client.innerApiCalls.removeControl = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.removeControl( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeControl with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedHeaderRequestParams = `serving_config=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.removeControl = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.removeControl(request), expectedError); - const actualRequest = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.removeControl as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes removeControl with closed client', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RemoveControlRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RemoveControlRequest', ['servingConfig']); - request.servingConfig = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.removeControl(request), expectedError); - }); - }); - - describe('listServingConfigs', () => { - it('invokes listServingConfigs without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - ]; - client.innerApiCalls.listServingConfigs = stubSimpleCall(expectedResponse); - const [response] = await client.listServingConfigs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServingConfigs without error using callback', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - ]; - client.innerApiCalls.listServingConfigs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listServingConfigs( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IServingConfig[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServingConfigs with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listServingConfigs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listServingConfigs(request), expectedError); - const actualRequest = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listServingConfigs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listServingConfigsStream without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - ]; - client.descriptors.page.listServingConfigs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listServingConfigsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.ServingConfig[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ServingConfig) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listServingConfigs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServingConfigs, request)); - assert( - (client.descriptors.page.listServingConfigs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listServingConfigsStream with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServingConfigs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listServingConfigsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.retail.v2alpha.ServingConfig[] = []; - stream.on('data', (response: protos.google.cloud.retail.v2alpha.ServingConfig) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listServingConfigs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listServingConfigs, request)); - assert( - (client.descriptors.page.listServingConfigs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServingConfigs without error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - generateSampleMessage(new protos.google.cloud.retail.v2alpha.ServingConfig()), - ]; - client.descriptors.page.listServingConfigs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.retail.v2alpha.IServingConfig[] = []; - const iterable = client.listServingConfigsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listServingConfigs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServingConfigs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listServingConfigs with error', async () => { - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ListServingConfigsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ListServingConfigsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listServingConfigs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listServingConfigsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.retail.v2alpha.IServingConfig[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listServingConfigs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listServingConfigs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new servingconfigserviceModule.v2alpha.ServingConfigServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_user_event_service_v2alpha.ts.baseline b/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_user_event_service_v2alpha.ts.baseline deleted file mode 100644 index 3ea4a094fcd0..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/retail/test/gapic_user_event_service_v2alpha.ts.baseline +++ /dev/null @@ -1,1625 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as usereventserviceModule from '../src'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v2alpha.UserEventServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = usereventserviceModule.v2alpha.UserEventServiceClient.servicePath; - assert.strictEqual(servicePath, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = usereventserviceModule.v2alpha.UserEventServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'retail.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'retail.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new usereventserviceModule.v2alpha.UserEventServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = usereventserviceModule.v2alpha.UserEventServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.userEventServiceStub, undefined); - await client.initialize(); - assert(client.userEventServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.userEventServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.userEventServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - 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); - }); - }); - - describe('writeUserEvent', () => { - it('invokes writeUserEvent without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.WriteUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.WriteUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UserEvent() - ); - client.innerApiCalls.writeUserEvent = stubSimpleCall(expectedResponse); - const [response] = await client.writeUserEvent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes writeUserEvent without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.WriteUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.WriteUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.UserEvent() - ); - client.innerApiCalls.writeUserEvent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.writeUserEvent( - request, - (err?: Error|null, result?: protos.google.cloud.retail.v2alpha.IUserEvent|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes writeUserEvent with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.WriteUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.WriteUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.writeUserEvent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.writeUserEvent(request), expectedError); - const actualRequest = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.writeUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes writeUserEvent with closed client', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.WriteUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.WriteUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.writeUserEvent(request), expectedError); - }); - }); - - describe('collectUserEvent', () => { - it('invokes collectUserEvent without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CollectUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CollectUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.HttpBody() - ); - client.innerApiCalls.collectUserEvent = stubSimpleCall(expectedResponse); - const [response] = await client.collectUserEvent(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes collectUserEvent without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CollectUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CollectUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.api.HttpBody() - ); - client.innerApiCalls.collectUserEvent = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.collectUserEvent( - request, - (err?: Error|null, result?: protos.google.api.IHttpBody|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes collectUserEvent with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CollectUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CollectUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.collectUserEvent = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.collectUserEvent(request), expectedError); - const actualRequest = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.collectUserEvent as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes collectUserEvent with closed client', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.CollectUserEventRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.CollectUserEventRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.collectUserEvent(request), expectedError); - }); - }); - - describe('purgeUserEvents', () => { - it('invokes purgeUserEvents without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.purgeUserEvents = stubLongRunningCall(expectedResponse); - const [operation] = await client.purgeUserEvents(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeUserEvents without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.purgeUserEvents = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.purgeUserEvents( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeUserEvents with call error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeUserEvents = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.purgeUserEvents(request), expectedError); - const actualRequest = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeUserEvents with LRO error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.PurgeUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.PurgeUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeUserEvents = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.purgeUserEvents(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkPurgeUserEventsProgress without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkPurgeUserEventsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkPurgeUserEventsProgress with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkPurgeUserEventsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('importUserEvents', () => { - it('invokes importUserEvents without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importUserEvents = stubLongRunningCall(expectedResponse); - const [operation] = await client.importUserEvents(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importUserEvents without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.importUserEvents = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.importUserEvents( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importUserEvents with call error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importUserEvents = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.importUserEvents(request), expectedError); - const actualRequest = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes importUserEvents with LRO error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ImportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ImportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.importUserEvents = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.importUserEvents(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.importUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkImportUserEventsProgress without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkImportUserEventsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkImportUserEventsProgress with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkImportUserEventsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('exportUserEvents', () => { - it('invokes exportUserEvents without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportUserEvents = stubLongRunningCall(expectedResponse); - const [operation] = await client.exportUserEvents(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportUserEvents without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.exportUserEvents = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.exportUserEvents( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportUserEvents with call error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportUserEvents = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.exportUserEvents(request), expectedError); - const actualRequest = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes exportUserEvents with LRO error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.ExportUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.ExportUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.exportUserEvents = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.exportUserEvents(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.exportUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkExportUserEventsProgress without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkExportUserEventsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkExportUserEventsProgress with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkExportUserEventsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('rejoinUserEvents', () => { - it('invokes rejoinUserEvents without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RejoinUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RejoinUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.rejoinUserEvents = stubLongRunningCall(expectedResponse); - const [operation] = await client.rejoinUserEvents(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rejoinUserEvents without error using callback', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RejoinUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RejoinUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.rejoinUserEvents = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.rejoinUserEvents( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rejoinUserEvents with call error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RejoinUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RejoinUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rejoinUserEvents = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.rejoinUserEvents(request), expectedError); - const actualRequest = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes rejoinUserEvents with LRO error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.retail.v2alpha.RejoinUserEventsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.retail.v2alpha.RejoinUserEventsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.rejoinUserEvents = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.rejoinUserEvents(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.rejoinUserEvents as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkRejoinUserEventsProgress without error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkRejoinUserEventsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkRejoinUserEventsProgress with error', async () => { - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkRejoinUserEventsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('Path templates', () => { - - describe('alertConfig', async () => { - const fakePath = "/rendered/path/alertConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.alertConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.alertConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('alertConfigPath', () => { - const result = client.alertConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.alertConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAlertConfigName', () => { - const result = client.matchProjectFromAlertConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.alertConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('attributesConfig', async () => { - const fakePath = "/rendered/path/attributesConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.attributesConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.attributesConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('attributesConfigPath', () => { - const result = client.attributesConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.attributesConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromAttributesConfigName', () => { - const result = client.matchProjectFromAttributesConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromAttributesConfigName', () => { - const result = client.matchLocationFromAttributesConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromAttributesConfigName', () => { - const result = client.matchCatalogFromAttributesConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.attributesConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('branch', async () => { - const fakePath = "/rendered/path/branch"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.branchPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.branchPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('branchPath', () => { - const result = client.branchPath("projectValue", "locationValue", "catalogValue", "branchValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.branchPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromBranchName', () => { - const result = client.matchProjectFromBranchName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromBranchName', () => { - const result = client.matchLocationFromBranchName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromBranchName', () => { - const result = client.matchCatalogFromBranchName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromBranchName', () => { - const result = client.matchBranchFromBranchName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.branchPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('catalog', async () => { - const fakePath = "/rendered/path/catalog"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.catalogPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.catalogPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('catalogPath', () => { - const result = client.catalogPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.catalogPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCatalogName', () => { - const result = client.matchProjectFromCatalogName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCatalogName', () => { - const result = client.matchLocationFromCatalogName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCatalogName', () => { - const result = client.matchCatalogFromCatalogName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.catalogPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('completionConfig', async () => { - const fakePath = "/rendered/path/completionConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.completionConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.completionConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('completionConfigPath', () => { - const result = client.completionConfigPath("projectValue", "locationValue", "catalogValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.completionConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromCompletionConfigName', () => { - const result = client.matchProjectFromCompletionConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromCompletionConfigName', () => { - const result = client.matchLocationFromCompletionConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromCompletionConfigName', () => { - const result = client.matchCatalogFromCompletionConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.completionConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('control', async () => { - const fakePath = "/rendered/path/control"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - control: "controlValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.controlPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.controlPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('controlPath', () => { - const result = client.controlPath("projectValue", "locationValue", "catalogValue", "controlValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.controlPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromControlName', () => { - const result = client.matchProjectFromControlName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromControlName', () => { - const result = client.matchLocationFromControlName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromControlName', () => { - const result = client.matchCatalogFromControlName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchControlFromControlName', () => { - const result = client.matchControlFromControlName(fakePath); - assert.strictEqual(result, "controlValue"); - assert((client.pathTemplates.controlPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('loggingConfig', async () => { - const fakePath = "/rendered/path/loggingConfig"; - const expectedParameters = { - project: "projectValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.loggingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.loggingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('loggingConfigPath', () => { - const result = client.loggingConfigPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.loggingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLoggingConfigName', () => { - const result = client.matchProjectFromLoggingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.loggingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('merchantCenterAccountLink', async () => { - const fakePath = "/rendered/path/merchantCenterAccountLink"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - merchant_center_account_link: "merchantCenterAccountLinkValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.merchantCenterAccountLinkPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('merchantCenterAccountLinkPath', () => { - const result = client.merchantCenterAccountLinkPath("projectValue", "locationValue", "catalogValue", "merchantCenterAccountLinkValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromMerchantCenterAccountLinkName', () => { - const result = client.matchProjectFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromMerchantCenterAccountLinkName', () => { - const result = client.matchLocationFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromMerchantCenterAccountLinkName', () => { - const result = client.matchCatalogFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName', () => { - const result = client.matchMerchantCenterAccountLinkFromMerchantCenterAccountLinkName(fakePath); - assert.strictEqual(result, "merchantCenterAccountLinkValue"); - assert((client.pathTemplates.merchantCenterAccountLinkPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('model', async () => { - const fakePath = "/rendered/path/model"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - model: "modelValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.modelPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.modelPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('modelPath', () => { - const result = client.modelPath("projectValue", "locationValue", "catalogValue", "modelValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.modelPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromModelName', () => { - const result = client.matchProjectFromModelName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromModelName', () => { - const result = client.matchLocationFromModelName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromModelName', () => { - const result = client.matchCatalogFromModelName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchModelFromModelName', () => { - const result = client.matchModelFromModelName(fakePath); - assert.strictEqual(result, "modelValue"); - assert((client.pathTemplates.modelPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('product', async () => { - const fakePath = "/rendered/path/product"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - branch: "branchValue", - product: "productValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.productPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.productPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('productPath', () => { - const result = client.productPath("projectValue", "locationValue", "catalogValue", "branchValue", "productValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.productPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProductName', () => { - const result = client.matchProjectFromProductName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromProductName', () => { - const result = client.matchLocationFromProductName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromProductName', () => { - const result = client.matchCatalogFromProductName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBranchFromProductName', () => { - const result = client.matchBranchFromProductName(fakePath); - assert.strictEqual(result, "branchValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchProductFromProductName', () => { - const result = client.matchProductFromProductName(fakePath); - assert.strictEqual(result, "productValue"); - assert((client.pathTemplates.productPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('retailProject', async () => { - const fakePath = "/rendered/path/retailProject"; - const expectedParameters = { - project: "projectValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.retailProjectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.retailProjectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('retailProjectPath', () => { - const result = client.retailProjectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.retailProjectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromRetailProjectName', () => { - const result = client.matchProjectFromRetailProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.retailProjectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('servingConfig', async () => { - const fakePath = "/rendered/path/servingConfig"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - catalog: "catalogValue", - serving_config: "servingConfigValue", - }; - const client = new usereventserviceModule.v2alpha.UserEventServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.servingConfigPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.servingConfigPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('servingConfigPath', () => { - const result = client.servingConfigPath("projectValue", "locationValue", "catalogValue", "servingConfigValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.servingConfigPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromServingConfigName', () => { - const result = client.matchProjectFromServingConfigName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromServingConfigName', () => { - const result = client.matchLocationFromServingConfigName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchCatalogFromServingConfigName', () => { - const result = client.matchCatalogFromServingConfigName(fakePath); - assert.strictEqual(result, "catalogValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchServingConfigFromServingConfigName', () => { - const result = client.matchServingConfigFromServingConfigName(fakePath); - assert.strictEqual(result, "servingConfigValue"); - assert((client.pathTemplates.servingConfigPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/retail/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/retail/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/retail/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/retail/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 3b32afa03b61..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const routingtest = require('routingtest'); - -function main() { - const testServiceClient = new routingtest.TestServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index d2d9aee6deb5..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as routingtest from 'routingtest'; - -function main() { - const testServiceClient = new routingtest.TestServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index a07bf100be47..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {TestServiceClient} from 'routingtest'; - -// check that the client class type name can be used -function doStuffWithTestServiceClient(client: TestServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const testServiceClient = new TestServiceClient(); - doStuffWithTestServiceClient(testServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/test/gapic_test_service_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/test/gapic_test_service_v1.ts.baseline deleted file mode 100644 index 274ac5a2f027..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/esm/test/gapic_test_service_v1.ts.baseline +++ /dev/null @@ -1,494 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as testserviceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1.TestServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new testserviceModule.v1.TestServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new testserviceModule.v1.TestServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = testserviceModule.v1.TestServiceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = testserviceModule.v1.TestServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new testserviceModule.v1.TestServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = testserviceModule.v1.TestServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new testserviceModule.v1.TestServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new testserviceModule.v1.TestServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testServiceStub, undefined); - await client.initialize(); - assert(client.testServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.testServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testserviceModule.v1.TestServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testserviceModule.v1.TestServiceClient({ - 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); - }); - }); - - describe('fastFibonacci', () => { - it('invokes fastFibonacci without error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {database=projects/*/databases/*}/documents - request.name = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'database=projects%2Fvalue%2Fdatabases%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.fastFibonacci = stubSimpleCall(expectedResponse); - const [response] = await client.fastFibonacci(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes fastFibonacci without error using callback', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {database=projects/*/databases/*}/documents - request.name = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'database=projects%2Fvalue%2Fdatabases%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.fastFibonacci = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.fastFibonacci( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes fastFibonacci with error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {database=projects/*/databases/*}/documents - request.name = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'database=projects%2Fvalue%2Fdatabases%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.fastFibonacci = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.fastFibonacci(request), expectedError); - const actualRequest = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes fastFibonacci with closed client', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {database=projects/*/databases/*}/documents - request.name = 'projects/value/databases/value/documents'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.fastFibonacci(request), expectedError); - }); - }); - - describe('randomFibonacci', () => { - it('invokes randomFibonacci without error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=**} - request.name = 'value'; - const expectedHeaderRequestParams = 'routing_id=value'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.randomFibonacci = stubSimpleCall(expectedResponse); - const [response] = await client.randomFibonacci(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes randomFibonacci without error using callback', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=**} - request.name = 'value'; - const expectedHeaderRequestParams = 'routing_id=value'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.randomFibonacci = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.randomFibonacci( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes randomFibonacci with error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=**} - request.name = 'value'; - const expectedHeaderRequestParams = 'routing_id=value'; - const expectedError = new Error('expected'); - client.innerApiCalls.randomFibonacci = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.randomFibonacci(request), expectedError); - const actualRequest = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes randomFibonacci with closed client', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=**} - request.name = 'value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.randomFibonacci(request), expectedError); - }); - }); - - describe('slowFibonacci', () => { - it('invokes slowFibonacci without error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=projects/*}/databases/*/documents - request.anotherParentId = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'routing_id=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.slowFibonacci = stubSimpleCall(expectedResponse); - const [response] = await client.slowFibonacci(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes slowFibonacci without error using callback', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=projects/*}/databases/*/documents - request.anotherParentId = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'routing_id=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.slowFibonacci = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.slowFibonacci( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes slowFibonacci with error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=projects/*}/databases/*/documents - request.anotherParentId = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'routing_id=projects%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.slowFibonacci = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.slowFibonacci(request), expectedError); - const actualRequest = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes slowFibonacci with closed client', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=projects/*}/databases/*/documents - request.anotherParentId = 'projects/value/databases/value/documents'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.slowFibonacci(request), expectedError); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/package.json b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/package.json index d4c5a67c414e..fb0212f46575 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/routingtest-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/routingtest/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/routingtest/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/package.json b/core/generator/gapic-generator-typescript/baselines/routingtest/package.json index 0ab0042ce5f7..6bac9cb2044e 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/package.json +++ b/core/generator/gapic-generator-typescript/baselines/routingtest/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 11226a0d230d..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const routingtest = require('routingtest'); - -function main() { - const testServiceClient = new routingtest.TestServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 2064c65d4c0c..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {TestServiceClient} from 'routingtest'; - -// check that the client class type name can be used -function doStuffWithTestServiceClient(client: TestServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const testServiceClient = new TestServiceClient(); - doStuffWithTestServiceClient(testServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/test/gapic_test_service_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/test/gapic_test_service_v1.ts.baseline deleted file mode 100644 index 8a360496e13f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/test/gapic_test_service_v1.ts.baseline +++ /dev/null @@ -1,485 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as testserviceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1.TestServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new testserviceModule.v1.TestServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new testserviceModule.v1.TestServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = testserviceModule.v1.TestServiceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = testserviceModule.v1.TestServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new testserviceModule.v1.TestServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = testserviceModule.v1.TestServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new testserviceModule.v1.TestServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new testserviceModule.v1.TestServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testServiceStub, undefined); - await client.initialize(); - assert(client.testServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.testServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testserviceModule.v1.TestServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testserviceModule.v1.TestServiceClient({ - 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); - }); - }); - - describe('fastFibonacci', () => { - it('invokes fastFibonacci without error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {database=projects/*/databases/*}/documents - request.name = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'database=projects%2Fvalue%2Fdatabases%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.fastFibonacci = stubSimpleCall(expectedResponse); - const [response] = await client.fastFibonacci(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes fastFibonacci without error using callback', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {database=projects/*/databases/*}/documents - request.name = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'database=projects%2Fvalue%2Fdatabases%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.fastFibonacci = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.fastFibonacci( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes fastFibonacci with error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {database=projects/*/databases/*}/documents - request.name = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'database=projects%2Fvalue%2Fdatabases%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.fastFibonacci = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.fastFibonacci(request), expectedError); - const actualRequest = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.fastFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes fastFibonacci with closed client', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {database=projects/*/databases/*}/documents - request.name = 'projects/value/databases/value/documents'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.fastFibonacci(request), expectedError); - }); - }); - - describe('randomFibonacci', () => { - it('invokes randomFibonacci without error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=**} - request.name = 'value'; - const expectedHeaderRequestParams = 'routing_id=value'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.randomFibonacci = stubSimpleCall(expectedResponse); - const [response] = await client.randomFibonacci(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes randomFibonacci without error using callback', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=**} - request.name = 'value'; - const expectedHeaderRequestParams = 'routing_id=value'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.randomFibonacci = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.randomFibonacci( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes randomFibonacci with error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=**} - request.name = 'value'; - const expectedHeaderRequestParams = 'routing_id=value'; - const expectedError = new Error('expected'); - client.innerApiCalls.randomFibonacci = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.randomFibonacci(request), expectedError); - const actualRequest = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.randomFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes randomFibonacci with closed client', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=**} - request.name = 'value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.randomFibonacci(request), expectedError); - }); - }); - - describe('slowFibonacci', () => { - it('invokes slowFibonacci without error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=projects/*}/databases/*/documents - request.anotherParentId = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'routing_id=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.slowFibonacci = stubSimpleCall(expectedResponse); - const [response] = await client.slowFibonacci(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes slowFibonacci without error using callback', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=projects/*}/databases/*/documents - request.anotherParentId = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'routing_id=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.slowFibonacci = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.slowFibonacci( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes slowFibonacci with error', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=projects/*}/databases/*/documents - request.anotherParentId = 'projects/value/databases/value/documents'; - const expectedHeaderRequestParams = 'routing_id=projects%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.slowFibonacci = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.slowFibonacci(request), expectedError); - const actualRequest = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.slowFibonacci as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes slowFibonacci with closed client', async () => { - const client = new testserviceModule.v1.TestServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.routingtest.v1.FibonacciRequest() - ); - // path template: {routing_id=projects/*}/databases/*/documents - request.anotherParentId = 'projects/value/databases/value/documents'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.slowFibonacci(request), expectedError); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/routingtest/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/routingtest/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/routingtest/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/routingtest/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index acd7e61b97d1..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const showcase = require('showcase'); - -function main() { - const complianceClient = new showcase.ComplianceClient(); - const echoClient = new showcase.EchoClient(); - const identityClient = new showcase.IdentityClient(); - const messagingClient = new showcase.MessagingClient(); - const sequenceServiceClient = new showcase.SequenceServiceClient(); - const testingClient = new showcase.TestingClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 156c00af163e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as showcase from 'showcase'; - -function main() { - const complianceClient = new showcase.ComplianceClient(); - const echoClient = new showcase.EchoClient(); - const identityClient = new showcase.IdentityClient(); - const messagingClient = new showcase.MessagingClient(); - const sequenceServiceClient = new showcase.SequenceServiceClient(); - const testingClient = new showcase.TestingClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 54230b252a83..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,63 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {ComplianceClient, EchoClient, IdentityClient, MessagingClient, SequenceServiceClient, TestingClient} from 'showcase'; - -// check that the client class type name can be used -function doStuffWithComplianceClient(client: ComplianceClient) { - client.close(); -} -function doStuffWithEchoClient(client: EchoClient) { - client.close(); -} -function doStuffWithIdentityClient(client: IdentityClient) { - client.close(); -} -function doStuffWithMessagingClient(client: MessagingClient) { - client.close(); -} -function doStuffWithSequenceServiceClient(client: SequenceServiceClient) { - client.close(); -} -function doStuffWithTestingClient(client: TestingClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const complianceClient = new ComplianceClient(); - doStuffWithComplianceClient(complianceClient); - // check that the client instance can be created - const echoClient = new EchoClient(); - doStuffWithEchoClient(echoClient); - // check that the client instance can be created - const identityClient = new IdentityClient(); - doStuffWithIdentityClient(identityClient); - // check that the client instance can be created - const messagingClient = new MessagingClient(); - doStuffWithMessagingClient(messagingClient); - // check that the client instance can be created - const sequenceServiceClient = new SequenceServiceClient(); - doStuffWithSequenceServiceClient(sequenceServiceClient); - // check that the client instance can be created - const testingClient = new TestingClient(); - doStuffWithTestingClient(testingClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_compliance_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_compliance_v1beta1.ts.baseline deleted file mode 100644 index 7403c5712d59..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_compliance_v1beta1.ts.baseline +++ /dev/null @@ -1,1568 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as complianceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1beta1.ComplianceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = complianceModule.v1beta1.ComplianceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = complianceModule.v1beta1.ComplianceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new complianceModule.v1beta1.ComplianceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = complianceModule.v1beta1.ComplianceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.complianceStub, undefined); - await client.initialize(); - assert(client.complianceStub); - }); - - it('has close method for the initialized client', done => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.complianceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.complianceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new complianceModule.v1beta1.ComplianceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new complianceModule.v1beta1.ComplianceClient({ - 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); - }); - }); - - describe('repeatDataBody', () => { - it('invokes repeatDataBody without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBody = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBody(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBody without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBody = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBody( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBody with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBody = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBody(request), expectedError); - }); - - it('invokes repeatDataBody with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBody(request), expectedError); - }); - }); - - describe('repeatDataBodyInfo', () => { - it('invokes repeatDataBodyInfo without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyInfo(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyInfo without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyInfo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyInfo with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyInfo(request), expectedError); - }); - - it('invokes repeatDataBodyInfo with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyInfo(request), expectedError); - }); - }); - - describe('repeatDataQuery', () => { - it('invokes repeatDataQuery without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataQuery = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataQuery(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataQuery without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataQuery = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataQuery( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataQuery with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataQuery = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataQuery(request), expectedError); - }); - - it('invokes repeatDataQuery with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataQuery(request), expectedError); - }); - }); - - describe('repeatDataSimplePath', () => { - it('invokes repeatDataSimplePath without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataSimplePath(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataSimplePath( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataSimplePath(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataSimplePath(request), expectedError); - }); - }); - - describe('repeatDataPathResource', () => { - it('invokes repeatDataPathResource without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathResource = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataPathResource(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathResource = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataPathResource( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataPathResource = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataPathResource(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataPathResource(request), expectedError); - }); - }); - - describe('repeatDataPathTrailingResource', () => { - it('invokes repeatDataPathTrailingResource without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataPathTrailingResource(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataPathTrailingResource( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataPathTrailingResource(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataPathTrailingResource(request), expectedError); - }); - }); - - describe('repeatDataBodyPut', () => { - it('invokes repeatDataBodyPut without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyPut(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPut without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyPut( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPut with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyPut(request), expectedError); - }); - - it('invokes repeatDataBodyPut with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyPut(request), expectedError); - }); - }); - - describe('repeatDataBodyPatch', () => { - it('invokes repeatDataBodyPatch without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyPatch(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPatch without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyPatch( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPatch with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyPatch(request), expectedError); - }); - - it('invokes repeatDataBodyPatch with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyPatch(request), expectedError); - }); - }); - - describe('getEnum', () => { - it('invokes getEnum without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.getEnum = stubSimpleCall(expectedResponse); - const [response] = await client.getEnum(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getEnum without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.getEnum = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getEnum( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEnumResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getEnum with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.getEnum = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getEnum(request), expectedError); - }); - - it('invokes getEnum with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getEnum(request), expectedError); - }); - }); - - describe('verifyEnum', () => { - it('invokes verifyEnum without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.verifyEnum = stubSimpleCall(expectedResponse); - const [response] = await client.verifyEnum(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes verifyEnum without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.verifyEnum = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyEnum( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEnumResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes verifyEnum with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.verifyEnum = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyEnum(request), expectedError); - }); - - it('invokes verifyEnum with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyEnum(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_echo_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_echo_v1beta1.ts.baseline deleted file mode 100644 index dbae7ddd07fc..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_echo_v1beta1.ts.baseline +++ /dev/null @@ -1,1543 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as echoModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.EchoClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new echoModule.v1beta1.EchoClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new echoModule.v1beta1.EchoClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = echoModule.v1beta1.EchoClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = echoModule.v1beta1.EchoClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new echoModule.v1beta1.EchoClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = echoModule.v1beta1.EchoClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new echoModule.v1beta1.EchoClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new echoModule.v1beta1.EchoClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - await client.initialize(); - assert(client.echoStub); - }); - - it('has close method for the initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.echoStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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); - }); - }); - - describe('echo', () => { - it('invokes echo without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCall(expectedResponse); - const [response] = await client.echo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - assert.match((client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0].requestId, /[a-z0-9-]{36}/) - }); - - it('invokes echo without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - assert.match((client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0].requestId, /[a-z0-9-]{36}/) - }); - - it('invokes echo with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echo(request), expectedError); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - assert.match((client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0].requestId, /[a-z0-9-]{36}/) - }); - - it('invokes echo with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echo(request), expectedError); - }); - }); - - describe('echoErrorDetails', () => { - it('invokes echoErrorDetails without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(expectedResponse); - const [response] = await client.echoErrorDetails(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echoErrorDetails( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoErrorDetailsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - - it('invokes echoErrorDetails with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - }); - - describe('pagedExpandLegacy', () => { - it('invokes pagedExpandLegacy without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpandLegacy(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpandLegacy( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IPagedExpandResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - - it('invokes pagedExpandLegacy with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - }); - - describe('block', () => { - it('invokes block without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCall(expectedResponse); - const [response] = await client.block(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.block( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlockResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.block = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.block(request), expectedError); - }); - - it('invokes block with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.block(request), expectedError); - }); - }); - - describe('wait', () => { - it('invokes wait without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCall(expectedResponse); - const [operation] = await client.wait(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.wait( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait with call error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.wait(request), expectedError); - }); - - it('invokes wait with LRO error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.wait(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkWaitProgress without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkWaitProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkWaitProgress with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkWaitProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('expand', () => { - it('invokes expand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand without error and gaxServerStreamingRetries enabled', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.expand = stubServerStreamingCall(undefined, expectedError); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - - it('invokes expand with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.expand(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new echoModule.v1beta1.EchoClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('chat', () => { - it('invokes chat without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.chat = stubBidiStreamingCall(expectedResponse); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes chat with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.chat = stubBidiStreamingCall(undefined, expectedError); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('collect', () => { - it('invokes collect without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.collect = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes collect with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.collect = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('pagedExpand', () => { - it('invokes pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpand(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpand( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpand = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpand(request), expectedError); - }); - - it('invokes pagedExpandStream without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('invokes pagedExpandStream with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('uses async iteration with pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - const iterable = client.pagedExpandAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.pagedExpandAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_identity_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_identity_v1beta1.ts.baseline deleted file mode 100644 index 2da43f67b837..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_identity_v1beta1.ts.baseline +++ /dev/null @@ -1,1212 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as identityModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.IdentityClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new identityModule.v1beta1.IdentityClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new identityModule.v1beta1.IdentityClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = identityModule.v1beta1.IdentityClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = identityModule.v1beta1.IdentityClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new identityModule.v1beta1.IdentityClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = identityModule.v1beta1.IdentityClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new identityModule.v1beta1.IdentityClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new identityModule.v1beta1.IdentityClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.identityStub, undefined); - await client.initialize(); - assert(client.identityStub); - }); - - it('has close method for the initialized client', done => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.identityStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.identityStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new identityModule.v1beta1.IdentityClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new identityModule.v1beta1.IdentityClient({ - 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); - }); - }); - - describe('createUser', () => { - it('invokes createUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.createUser = stubSimpleCall(expectedResponse); - const [response] = await client.createUser(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.createUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createUser(request), expectedError); - }); - - it('invokes createUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createUser(request), expectedError); - }); - }); - - describe('getUser', () => { - it('invokes getUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.getUser = stubSimpleCall(expectedResponse); - const [response] = await client.getUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.getUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getUser(request), expectedError); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getUser(request), expectedError); - }); - }); - - describe('updateUser', () => { - it('invokes updateUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.updateUser = stubSimpleCall(expectedResponse); - const [response] = await client.updateUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.updateUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateUser(request), expectedError); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateUser(request), expectedError); - }); - }); - - describe('deleteUser', () => { - it('invokes deleteUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUser = stubSimpleCall(expectedResponse); - const [response] = await client.deleteUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteUser( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteUser(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteUser(request), expectedError); - }); - }); - - describe('listUsers', () => { - it('invokes listUsers without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.innerApiCalls.listUsers = stubSimpleCall(expectedResponse); - const [response] = await client.listUsers(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUsers without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.innerApiCalls.listUsers = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUsers( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUsers with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listUsers = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listUsers(request), expectedError); - }); - - it('invokes listUsersStream without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.descriptors.page.listUsers.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listUsersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.User[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.User) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listUsers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUsers, request)); - }); - - it('invokes listUsersStream with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUsers.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listUsersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.User[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.User) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listUsers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUsers, request)); - }); - - it('uses async iteration with listUsers without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.descriptors.page.listUsers.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IUser[] = []; - const iterable = client.listUsersAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listUsers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listUsers with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUsers.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listUsersAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IUser[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listUsers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_messaging_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_messaging_v1beta1.ts.baseline deleted file mode 100644 index e65f87dfaf42..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_messaging_v1beta1.ts.baseline +++ /dev/null @@ -1,2364 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as messagingModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.MessagingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = messagingModule.v1beta1.MessagingClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = messagingModule.v1beta1.MessagingClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new messagingModule.v1beta1.MessagingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = messagingModule.v1beta1.MessagingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new messagingModule.v1beta1.MessagingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.messagingStub, undefined); - await client.initialize(); - assert(client.messagingStub); - }); - - it('has close method for the initialized client', done => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.messagingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.messagingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new messagingModule.v1beta1.MessagingClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new messagingModule.v1beta1.MessagingClient({ - 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); - }); - }); - - describe('createRoom', () => { - it('invokes createRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.createRoom = stubSimpleCall(expectedResponse); - const [response] = await client.createRoom(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.createRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createRoom(request), expectedError); - }); - - it('invokes createRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createRoom(request), expectedError); - }); - }); - - describe('getRoom', () => { - it('invokes getRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.getRoom = stubSimpleCall(expectedResponse); - const [response] = await client.getRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.getRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getRoom(request), expectedError); - }); - }); - - describe('updateRoom', () => { - it('invokes updateRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.updateRoom = stubSimpleCall(expectedResponse); - const [response] = await client.updateRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.updateRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateRoom(request), expectedError); - }); - }); - - describe('deleteRoom', () => { - it('invokes deleteRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoom = stubSimpleCall(expectedResponse); - const [response] = await client.deleteRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteRoom( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteRoom(request), expectedError); - }); - }); - - describe('createBlurb', () => { - it('invokes createBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.createBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.createBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.createBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createBlurb(request), expectedError); - }); - }); - - describe('getBlurb', () => { - it('invokes getBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.getBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.getBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.getBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBlurb(request), expectedError); - }); - }); - - describe('updateBlurb', () => { - it('invokes updateBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.updateBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.updateBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.updateBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateBlurb(request), expectedError); - }); - }); - - describe('deleteBlurb', () => { - it('invokes deleteBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBlurb( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteBlurb(request), expectedError); - }); - }); - - describe('searchBlurbs', () => { - it('invokes searchBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(expectedResponse); - const [operation] = await client.searchBlurbs(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.searchBlurbs = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.searchBlurbs( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs with call error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.searchBlurbs(request), expectedError); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs with LRO error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.searchBlurbs(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkSearchBlurbsProgress without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkSearchBlurbsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkSearchBlurbsProgress with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkSearchBlurbsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('streamBlurbs', () => { - it('invokes streamBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs without error and gaxServerStreamingRetries enabled', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(undefined, expectedError); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.streamBlurbs(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new messagingModule.v1beta1.MessagingClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('connect', () => { - it('invokes connect without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ConnectRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.connect = stubBidiStreamingCall(expectedResponse); - const stream = client.connect(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.connect as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes connect with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ConnectRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.connect = stubBidiStreamingCall(undefined, expectedError); - const stream = client.connect(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.connect as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('sendBlurbs', () => { - it('invokes sendBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SendBlurbsResponse() - ); - client.innerApiCalls.sendBlurbs = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.sendBlurbs( - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISendBlurbsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.sendBlurbs as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes sendBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.sendBlurbs = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.sendBlurbs( - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISendBlurbsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.sendBlurbs as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('listRooms', () => { - it('invokes listRooms without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.innerApiCalls.listRooms = stubSimpleCall(expectedResponse); - const [response] = await client.listRooms(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listRooms without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.innerApiCalls.listRooms = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listRooms( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listRooms with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listRooms = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listRooms(request), expectedError); - }); - - it('invokes listRoomsStream without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.descriptors.page.listRooms.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listRoomsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Room[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Room) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listRooms.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRooms, request)); - }); - - it('invokes listRoomsStream with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listRooms.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listRoomsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Room[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Room) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listRooms.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRooms, request)); - }); - - it('uses async iteration with listRooms without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.descriptors.page.listRooms.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IRoom[] = []; - const iterable = client.listRoomsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRooms.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listRooms with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listRooms.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listRoomsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IRoom[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRooms.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listBlurbs', () => { - it('invokes listBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.innerApiCalls.listBlurbs = stubSimpleCall(expectedResponse); - const [response] = await client.listBlurbs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbs without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.innerApiCalls.listBlurbs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBlurbs( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBlurbs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBlurbs(request), expectedError); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbsStream without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.descriptors.page.listBlurbs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listBlurbsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Blurb[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Blurb) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBlurbs, request)); - assert( - (client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listBlurbsStream with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBlurbs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listBlurbsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Blurb[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Blurb) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBlurbs, request)); - assert( - (client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.descriptors.page.listBlurbs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IBlurb[] = []; - const iterable = client.listBlurbsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBlurbs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBlurbsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IBlurb[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_sequence_service_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_sequence_service_v1beta1.ts.baseline deleted file mode 100644 index 6ad653d66ad9..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_sequence_service_v1beta1.ts.baseline +++ /dev/null @@ -1,878 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as sequenceserviceModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1beta1.SequenceServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = sequenceserviceModule.v1beta1.SequenceServiceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sequenceserviceModule.v1beta1.SequenceServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sequenceserviceModule.v1beta1.SequenceServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = sequenceserviceModule.v1beta1.SequenceServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sequenceServiceStub, undefined); - await client.initialize(); - assert(client.sequenceServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sequenceServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sequenceServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - 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); - }); - }); - - describe('createSequence', () => { - it('invokes createSequence without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Sequence() - ); - client.innerApiCalls.createSequence = stubSimpleCall(expectedResponse); - const [response] = await client.createSequence(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSequence without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Sequence() - ); - client.innerApiCalls.createSequence = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSequence( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISequence|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSequence with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createSequence = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSequence(request), expectedError); - }); - - it('invokes createSequence with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSequence(request), expectedError); - }); - }); - - describe('getSequenceReport', () => { - it('invokes getSequenceReport without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SequenceReport() - ); - client.innerApiCalls.getSequenceReport = stubSimpleCall(expectedResponse); - const [response] = await client.getSequenceReport(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SequenceReport() - ); - client.innerApiCalls.getSequenceReport = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSequenceReport( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISequenceReport|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSequenceReport = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSequenceReport(request), expectedError); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSequenceReport(request), expectedError); - }); - }); - - describe('attemptSequence', () => { - it('invokes attemptSequence without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.attemptSequence = stubSimpleCall(expectedResponse); - const [response] = await client.attemptSequence(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.attemptSequence = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.attemptSequence( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.attemptSequence = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.attemptSequence(request), expectedError); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.attemptSequence(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_testing_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_testing_v1beta1.ts.baseline deleted file mode 100644 index f19fcdb3cbb3..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/esm/test/gapic_testing_v1beta1.ts.baseline +++ /dev/null @@ -1,1669 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as testingModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.TestingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new testingModule.v1beta1.TestingClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new testingModule.v1beta1.TestingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = testingModule.v1beta1.TestingClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = testingModule.v1beta1.TestingClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new testingModule.v1beta1.TestingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = testingModule.v1beta1.TestingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new testingModule.v1beta1.TestingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new testingModule.v1beta1.TestingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testingStub, undefined); - await client.initialize(); - assert(client.testingStub); - }); - - it('has close method for the initialized client', done => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.testingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testingModule.v1beta1.TestingClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testingModule.v1beta1.TestingClient({ - 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); - }); - }); - - describe('createSession', () => { - it('invokes createSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.createSession = stubSimpleCall(expectedResponse); - const [response] = await client.createSession(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.createSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSession(request), expectedError); - }); - - it('invokes createSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSession(request), expectedError); - }); - }); - - describe('getSession', () => { - it('invokes getSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.getSession = stubSimpleCall(expectedResponse); - const [response] = await client.getSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.getSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSession(request), expectedError); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSession(request), expectedError); - }); - }); - - describe('deleteSession', () => { - it('invokes deleteSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSession = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSession( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSession(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteSession(request), expectedError); - }); - }); - - describe('reportSession', () => { - it('invokes reportSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionResponse() - ); - client.innerApiCalls.reportSession = stubSimpleCall(expectedResponse); - const [response] = await client.reportSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionResponse() - ); - client.innerApiCalls.reportSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.reportSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IReportSessionResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.reportSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.reportSession(request), expectedError); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.reportSession(request), expectedError); - }); - }); - - describe('deleteTest', () => { - it('invokes deleteTest without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTest = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTest(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTest = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTest( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTest = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTest(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteTest(request), expectedError); - }); - }); - - describe('verifyTest', () => { - it('invokes verifyTest without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestResponse() - ); - client.innerApiCalls.verifyTest = stubSimpleCall(expectedResponse); - const [response] = await client.verifyTest(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestResponse() - ); - client.innerApiCalls.verifyTest = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyTest( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IVerifyTestResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.verifyTest = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyTest(request), expectedError); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyTest(request), expectedError); - }); - }); - - describe('listSessions', () => { - it('invokes listSessions without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.innerApiCalls.listSessions = stubSimpleCall(expectedResponse); - const [response] = await client.listSessions(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listSessions without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.innerApiCalls.listSessions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSessions( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listSessions with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listSessions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSessions(request), expectedError); - }); - - it('invokes listSessionsStream without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.descriptors.page.listSessions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSessionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Session[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Session) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listSessions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSessions, request)); - }); - - it('invokes listSessionsStream with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listSessions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSessionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Session[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Session) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSessions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSessions, request)); - }); - - it('uses async iteration with listSessions without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.descriptors.page.listSessions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.ISession[] = []; - const iterable = client.listSessionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSessions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listSessions with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listSessions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSessionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.ISession[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSessions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listTests', () => { - it('invokes listTests without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.innerApiCalls.listTests = stubSimpleCall(expectedResponse); - const [response] = await client.listTests(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTests without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.innerApiCalls.listTests = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTests( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ITest[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTests with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTests = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTests(request), expectedError); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTestsStream without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.descriptors.page.listTests.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTestsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Test[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Test) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTests, request)); - assert( - (client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTestsStream with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTests.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTestsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Test[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Test) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTests, request)); - assert( - (client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTests without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.descriptors.page.listTests.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.ITest[] = []; - const iterable = client.listTestsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTests with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTests.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTestsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.ITest[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/package.json b/core/generator/gapic-generator-typescript/baselines/showcase-esm/package.json index 6de66ad2bdaf..6df8dd8f0209 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/showcase-esm/package.json @@ -65,12 +65,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -85,21 +79,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index e8ca2ec96597..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const showcase = require('showcase'); - -function main() { - const echoClient = new showcase.EchoClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index dc2f0f6ff5f5..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as showcase from 'showcase'; - -function main() { - const echoClient = new showcase.EchoClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 1e660d0737f9..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {EchoClient} from 'showcase'; - -// check that the client class type name can be used -function doStuffWithEchoClient(client: EchoClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const echoClient = new EchoClient(); - doStuffWithEchoClient(echoClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/test/gapic_echo_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/test/gapic_echo_v1beta1.ts.baseline deleted file mode 100644 index 047db4ae9dda..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/esm/test/gapic_echo_v1beta1.ts.baseline +++ /dev/null @@ -1,1111 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as echoModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - // non-string x-goog-request-param values are not supported; - // we always assume that it's a string. - return ''; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.EchoClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new echoModule.v1beta1.EchoClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new echoModule.v1beta1.EchoClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = echoModule.v1beta1.EchoClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = echoModule.v1beta1.EchoClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new echoModule.v1beta1.EchoClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = echoModule.v1beta1.EchoClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new echoModule.v1beta1.EchoClient(); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - await client.initialize(); - assert(client.echoStub); - }); - - it('has close method for the initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.echoStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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); - }); - }); - - describe('echo', () => { - it('invokes echo without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCall(expectedResponse); - const [response] = await client.echo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echo(request), expectedError); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echo(request), expectedError); - }); - }); - - describe('echoErrorDetails', () => { - it('invokes echoErrorDetails without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(expectedResponse); - const [response] = await client.echoErrorDetails(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echoErrorDetails( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoErrorDetailsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - - it('invokes echoErrorDetails with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - }); - - describe('pagedExpandLegacy', () => { - it('invokes pagedExpandLegacy without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpandLegacy(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpandLegacy( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IPagedExpandResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - - it('invokes pagedExpandLegacy with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - }); - - describe('block', () => { - it('invokes block without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCall(expectedResponse); - const [response] = await client.block(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.block( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlockResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.block = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.block(request), expectedError); - }); - - it('invokes block with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.block(request), expectedError); - }); - }); - - describe('wait', () => { - it('invokes wait without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCall(expectedResponse); - const [operation] = await client.wait(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.wait( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait with call error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.wait(request), expectedError); - }); - - it('invokes wait with LRO error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.wait(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkWaitProgress without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkWaitProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkWaitProgress with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkWaitProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('expand', () => { - it('invokes expand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand without error and gaxServerStreamingRetries enabled', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.expand = stubServerStreamingCall(undefined, expectedError); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - - it('invokes expand with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.expand(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new echoModule.v1beta1.EchoClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('chat', () => { - it('invokes chat without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.chat = stubBidiStreamingCall(expectedResponse); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes chat with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.chat = stubBidiStreamingCall(undefined, expectedError); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('collect', () => { - it('invokes collect without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.collect = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes collect with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.collect = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('pagedExpand', () => { - it('invokes pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpand(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpand( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpand = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpand(request), expectedError); - }); - - it('invokes pagedExpandStream without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('invokes pagedExpandStream with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('uses async iteration with pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - const iterable = client.pagedExpandAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.pagedExpandAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/package.json b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/package.json index 14a70ca73ffb..a5448bf1b8cd 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/package.json b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/package.json index a77345c1a7cf..8bd31e50bb81 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/package.json +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index f396c191bad8..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const showcase = require('showcase'); - -function main() { - const echoClient = new showcase.EchoClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 8a0366728d76..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {EchoClient} from 'showcase'; - -// check that the client class type name can be used -function doStuffWithEchoClient(client: EchoClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const echoClient = new EchoClient(); - doStuffWithEchoClient(echoClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/test/gapic_echo_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/test/gapic_echo_v1beta1.ts.baseline deleted file mode 100644 index 338049d52e79..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/test/gapic_echo_v1beta1.ts.baseline +++ /dev/null @@ -1,1111 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as echoModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - // non-string x-goog-request-param values are not supported; - // we always assume that it's a string. - return ''; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.EchoClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new echoModule.v1beta1.EchoClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new echoModule.v1beta1.EchoClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = echoModule.v1beta1.EchoClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = echoModule.v1beta1.EchoClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new echoModule.v1beta1.EchoClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = echoModule.v1beta1.EchoClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new echoModule.v1beta1.EchoClient(); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - await client.initialize(); - assert(client.echoStub); - }); - - it('has close method for the initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.echoStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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); - }); - }); - - describe('echo', () => { - it('invokes echo without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCall(expectedResponse); - const [response] = await client.echo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echo(request), expectedError); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes echo with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echo(request), expectedError); - }); - }); - - describe('echoErrorDetails', () => { - it('invokes echoErrorDetails without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(expectedResponse); - const [response] = await client.echoErrorDetails(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echoErrorDetails( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoErrorDetailsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - - it('invokes echoErrorDetails with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - }); - - describe('pagedExpandLegacy', () => { - it('invokes pagedExpandLegacy without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpandLegacy(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpandLegacy( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IPagedExpandResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - - it('invokes pagedExpandLegacy with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - }); - - describe('block', () => { - it('invokes block without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCall(expectedResponse); - const [response] = await client.block(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.block( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlockResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.block = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.block(request), expectedError); - }); - - it('invokes block with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.block(request), expectedError); - }); - }); - - describe('wait', () => { - it('invokes wait without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCall(expectedResponse); - const [operation] = await client.wait(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.wait( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait with call error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.wait(request), expectedError); - }); - - it('invokes wait with LRO error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.wait(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkWaitProgress without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkWaitProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkWaitProgress with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkWaitProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('expand', () => { - it('invokes expand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand without error and gaxServerStreamingRetries enabled', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.expand = stubServerStreamingCall(undefined, expectedError); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - - it('invokes expand with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.expand(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new echoModule.v1beta1.EchoClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('chat', () => { - it('invokes chat without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.chat = stubBidiStreamingCall(expectedResponse); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes chat with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.chat = stubBidiStreamingCall(undefined, expectedError); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('collect', () => { - it('invokes collect without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.collect = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes collect with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.collect = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('pagedExpand', () => { - it('invokes pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpand(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpand( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpand = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpand(request), expectedError); - }); - - it('invokes pagedExpandStream without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('invokes pagedExpandStream with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('uses async iteration with pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - const iterable = client.pagedExpandAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.pagedExpandAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase-legacy/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase-legacy/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/package.json b/core/generator/gapic-generator-typescript/baselines/showcase/package.json index e02a97d7b12a..d12cb40851b5 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase/package.json +++ b/core/generator/gapic-generator-typescript/baselines/showcase/package.json @@ -35,27 +35,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index a284de22984e..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const showcase = require('showcase'); - -function main() { - const complianceClient = new showcase.ComplianceClient(); - const echoClient = new showcase.EchoClient(); - const identityClient = new showcase.IdentityClient(); - const messagingClient = new showcase.MessagingClient(); - const sequenceServiceClient = new showcase.SequenceServiceClient(); - const testingClient = new showcase.TestingClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 889fe60d8ffc..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {ComplianceClient, EchoClient, IdentityClient, MessagingClient, SequenceServiceClient, TestingClient} from 'showcase'; - -// check that the client class type name can be used -function doStuffWithComplianceClient(client: ComplianceClient) { - client.close(); -} -function doStuffWithEchoClient(client: EchoClient) { - client.close(); -} -function doStuffWithIdentityClient(client: IdentityClient) { - client.close(); -} -function doStuffWithMessagingClient(client: MessagingClient) { - client.close(); -} -function doStuffWithSequenceServiceClient(client: SequenceServiceClient) { - client.close(); -} -function doStuffWithTestingClient(client: TestingClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const complianceClient = new ComplianceClient(); - doStuffWithComplianceClient(complianceClient); - // check that the client instance can be created - const echoClient = new EchoClient(); - doStuffWithEchoClient(echoClient); - // check that the client instance can be created - const identityClient = new IdentityClient(); - doStuffWithIdentityClient(identityClient); - // check that the client instance can be created - const messagingClient = new MessagingClient(); - doStuffWithMessagingClient(messagingClient); - // check that the client instance can be created - const sequenceServiceClient = new SequenceServiceClient(); - doStuffWithSequenceServiceClient(sequenceServiceClient); - // check that the client instance can be created - const testingClient = new TestingClient(); - doStuffWithTestingClient(testingClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_compliance_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_compliance_v1beta1.ts.baseline deleted file mode 100644 index 33c4db06519a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_compliance_v1beta1.ts.baseline +++ /dev/null @@ -1,1559 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as complianceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1beta1.ComplianceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = complianceModule.v1beta1.ComplianceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = complianceModule.v1beta1.ComplianceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new complianceModule.v1beta1.ComplianceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = complianceModule.v1beta1.ComplianceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new complianceModule.v1beta1.ComplianceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.complianceStub, undefined); - await client.initialize(); - assert(client.complianceStub); - }); - - it('has close method for the initialized client', done => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.complianceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.complianceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new complianceModule.v1beta1.ComplianceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new complianceModule.v1beta1.ComplianceClient({ - 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); - }); - }); - - describe('repeatDataBody', () => { - it('invokes repeatDataBody without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBody = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBody(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBody without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBody = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBody( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBody with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBody = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBody(request), expectedError); - }); - - it('invokes repeatDataBody with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBody(request), expectedError); - }); - }); - - describe('repeatDataBodyInfo', () => { - it('invokes repeatDataBodyInfo without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyInfo(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyInfo without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyInfo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyInfo with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyInfo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyInfo(request), expectedError); - }); - - it('invokes repeatDataBodyInfo with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyInfo(request), expectedError); - }); - }); - - describe('repeatDataQuery', () => { - it('invokes repeatDataQuery without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataQuery = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataQuery(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataQuery without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataQuery = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataQuery( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataQuery with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataQuery = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataQuery(request), expectedError); - }); - - it('invokes repeatDataQuery with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataQuery(request), expectedError); - }); - }); - - describe('repeatDataSimplePath', () => { - it('invokes repeatDataSimplePath without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataSimplePath(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataSimplePath( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_int32=${defaultValue2 ?? '' }&info.f_double=${defaultValue3 ?? '' }&info.f_bool=${defaultValue4 ?? '' }&info.f_kingdom=${defaultValue5 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataSimplePath = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataSimplePath(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataSimplePath as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataSimplePath with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fInt32']); - request.info.fInt32 = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fDouble']); - request.info.fDouble = defaultValue3; - request.info ??= {}; - const defaultValue4 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue4; - request.info ??= {}; - const defaultValue5 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fKingdom']); - request.info.fKingdom = defaultValue5; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataSimplePath(request), expectedError); - }); - }); - - describe('repeatDataPathResource', () => { - it('invokes repeatDataPathResource without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathResource = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataPathResource(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathResource = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataPathResource( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }&info.f_bool=${defaultValue3 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataPathResource = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataPathResource(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathResource with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - request.info ??= {}; - const defaultValue3 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fBool']); - request.info.fBool = defaultValue3; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataPathResource(request), expectedError); - }); - }); - - describe('repeatDataPathTrailingResource', () => { - it('invokes repeatDataPathTrailingResource without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataPathTrailingResource(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataPathTrailingResource( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedHeaderRequestParams = `info.f_string=${defaultValue1 ?? '' }&info.f_child.f_string=${defaultValue2 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataPathTrailingResource = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataPathTrailingResource(request), expectedError); - const actualRequest = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.repeatDataPathTrailingResource as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes repeatDataPathTrailingResource with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - request.info ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fString']); - request.info.fString = defaultValue1; - request.info ??= {}; - request.info.fChild ??= {}; - const defaultValue2 = - getTypeDefaultValue('.google.showcase.v1beta1.RepeatRequest', ['info', 'fChild', 'fString']); - request.info.fChild.fString = defaultValue2; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataPathTrailingResource(request), expectedError); - }); - }); - - describe('repeatDataBodyPut', () => { - it('invokes repeatDataBodyPut without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyPut(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPut without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyPut( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPut with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyPut = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyPut(request), expectedError); - }); - - it('invokes repeatDataBodyPut with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyPut(request), expectedError); - }); - }); - - describe('repeatDataBodyPatch', () => { - it('invokes repeatDataBodyPatch without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCall(expectedResponse); - const [response] = await client.repeatDataBodyPatch(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPatch without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatResponse() - ); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.repeatDataBodyPatch( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRepeatResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes repeatDataBodyPatch with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.repeatDataBodyPatch = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.repeatDataBodyPatch(request), expectedError); - }); - - it('invokes repeatDataBodyPatch with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.RepeatRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.repeatDataBodyPatch(request), expectedError); - }); - }); - - describe('getEnum', () => { - it('invokes getEnum without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.getEnum = stubSimpleCall(expectedResponse); - const [response] = await client.getEnum(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getEnum without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.getEnum = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getEnum( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEnumResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes getEnum with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.getEnum = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getEnum(request), expectedError); - }); - - it('invokes getEnum with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getEnum(request), expectedError); - }); - }); - - describe('verifyEnum', () => { - it('invokes verifyEnum without error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.verifyEnum = stubSimpleCall(expectedResponse); - const [response] = await client.verifyEnum(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes verifyEnum without error using callback', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - client.innerApiCalls.verifyEnum = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyEnum( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEnumResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes verifyEnum with error', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.verifyEnum = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyEnum(request), expectedError); - }); - - it('invokes verifyEnum with closed client', async () => { - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EnumResponse() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyEnum(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new complianceModule.v1beta1.ComplianceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_echo_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_echo_v1beta1.ts.baseline deleted file mode 100644 index 1a1ffd031a22..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_echo_v1beta1.ts.baseline +++ /dev/null @@ -1,1535 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as echoModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.EchoClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new echoModule.v1beta1.EchoClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new echoModule.v1beta1.EchoClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = echoModule.v1beta1.EchoClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = echoModule.v1beta1.EchoClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new echoModule.v1beta1.EchoClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = echoModule.v1beta1.EchoClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new echoModule.v1beta1.EchoClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new echoModule.v1beta1.EchoClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - await client.initialize(); - assert(client.echoStub); - }); - - it('has close method for the initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.echoStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.echoStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new echoModule.v1beta1.EchoClient({ - 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); - }); - }); - - describe('echo', () => { - it('invokes echo without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCall(expectedResponse); - const [response] = await client.echo(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - assert.match((client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0].requestId, /[a-z0-9-]{36}/) - }); - - it('invokes echo without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.echo = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echo( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - assert.match((client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0].requestId, /[a-z0-9-]{36}/) - }); - - it('invokes echo with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedHeaderRequestParams = 'qux=projects%2Fvalue'; - const expectedError = new Error('expected'); - client.innerApiCalls.echo = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echo(request), expectedError); - const actualRequest = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.echo as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - assert.match((client.innerApiCalls.echo as SinonStub) - .getCall(0).args[0].requestId, /[a-z0-9-]{36}/) - }); - - it('invokes echo with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - // path template: {qux=projects/*}/** - request.otherHeader = 'projects/value/value'; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echo(request), expectedError); - }); - }); - - describe('echoErrorDetails', () => { - it('invokes echoErrorDetails without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(expectedResponse); - const [response] = await client.echoErrorDetails(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsResponse() - ); - client.innerApiCalls.echoErrorDetails = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.echoErrorDetails( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoErrorDetailsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes echoErrorDetails with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.echoErrorDetails = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - - it('invokes echoErrorDetails with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoErrorDetailsRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.echoErrorDetails(request), expectedError); - }); - }); - - describe('pagedExpandLegacy', () => { - it('invokes pagedExpandLegacy without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpandLegacy(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandResponse() - ); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpandLegacy( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IPagedExpandResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpandLegacy with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpandLegacy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - - it('invokes pagedExpandLegacy with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandLegacyRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pagedExpandLegacy(request), expectedError); - }); - }); - - describe('block', () => { - it('invokes block without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCall(expectedResponse); - const [response] = await client.block(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockResponse() - ); - client.innerApiCalls.block = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.block( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlockResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes block with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.block = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.block(request), expectedError); - }); - - it('invokes block with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.BlockRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.block(request), expectedError); - }); - }); - - describe('wait', () => { - it('invokes wait without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCall(expectedResponse); - const [operation] = await client.wait(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.wait = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.wait( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes wait with call error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.wait(request), expectedError); - }); - - it('invokes wait with LRO error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.WaitRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.wait = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.wait(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkWaitProgress without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkWaitProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkWaitProgress with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkWaitProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('expand', () => { - it('invokes expand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand without error and gaxServerStreamingRetries enabled', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes expand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.expand = stubServerStreamingCall(undefined, expectedError); - const stream = client.expand(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - - it('invokes expand with closed client', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ExpandRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.expand(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new echoModule.v1beta1.EchoClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('chat', () => { - it('invokes chat without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.chat = stubBidiStreamingCall(expectedResponse); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes chat with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.chat = stubBidiStreamingCall(undefined, expectedError); - const stream = client.chat(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.chat as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('collect', () => { - it('invokes collect without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoResponse() - ); - client.innerApiCalls.collect = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes collect with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.EchoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.collect = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.collect( - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.collect as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('pagedExpand', () => { - it('invokes pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCall(expectedResponse); - const [response] = await client.pagedExpand(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand without error using callback', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.innerApiCalls.pagedExpand = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pagedExpand( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoResponse[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.pagedExpand = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pagedExpand(request), expectedError); - }); - - it('invokes pagedExpandStream without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('invokes pagedExpandStream with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.pagedExpandStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.EchoResponse[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.pagedExpand.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.pagedExpand, request)); - }); - - it('uses async iteration with pagedExpand without error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - generateSampleMessage(new protos.google.showcase.v1beta1.EchoResponse()), - ]; - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - const iterable = client.pagedExpandAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with pagedExpand with error', async () => { - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.PagedExpandRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.pagedExpand.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.pagedExpandAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IEchoResponse[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.pagedExpand.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new echoModule.v1beta1.EchoClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_identity_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_identity_v1beta1.ts.baseline deleted file mode 100644 index b938f6196ed4..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_identity_v1beta1.ts.baseline +++ /dev/null @@ -1,1203 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as identityModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.IdentityClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new identityModule.v1beta1.IdentityClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new identityModule.v1beta1.IdentityClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = identityModule.v1beta1.IdentityClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = identityModule.v1beta1.IdentityClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new identityModule.v1beta1.IdentityClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = identityModule.v1beta1.IdentityClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new identityModule.v1beta1.IdentityClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new identityModule.v1beta1.IdentityClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.identityStub, undefined); - await client.initialize(); - assert(client.identityStub); - }); - - it('has close method for the initialized client', done => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.identityStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.identityStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new identityModule.v1beta1.IdentityClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new identityModule.v1beta1.IdentityClient({ - 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); - }); - }); - - describe('createUser', () => { - it('invokes createUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.createUser = stubSimpleCall(expectedResponse); - const [response] = await client.createUser(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.createUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createUser(request), expectedError); - }); - - it('invokes createUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateUserRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createUser(request), expectedError); - }); - }); - - describe('getUser', () => { - it('invokes getUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.getUser = stubSimpleCall(expectedResponse); - const [response] = await client.getUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.getUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getUser(request), expectedError); - const actualRequest = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetUserRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getUser(request), expectedError); - }); - }); - - describe('updateUser', () => { - it('invokes updateUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.updateUser = stubSimpleCall(expectedResponse); - const [response] = await client.updateUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.User() - ); - client.innerApiCalls.updateUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateUser( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedHeaderRequestParams = `user.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateUser(request), expectedError); - const actualRequest = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateUserRequest() - ); - request.user ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateUserRequest', ['user', 'name']); - request.user.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateUser(request), expectedError); - }); - }); - - describe('deleteUser', () => { - it('invokes deleteUser without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUser = stubSimpleCall(expectedResponse); - const [response] = await client.deleteUser(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteUser = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteUser( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteUser = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteUser(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteUser as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteUser with closed client', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteUserRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteUserRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteUser(request), expectedError); - }); - }); - - describe('listUsers', () => { - it('invokes listUsers without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.innerApiCalls.listUsers = stubSimpleCall(expectedResponse); - const [response] = await client.listUsers(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUsers without error using callback', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.innerApiCalls.listUsers = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listUsers( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IUser[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listUsers with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listUsers = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listUsers(request), expectedError); - }); - - it('invokes listUsersStream without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.descriptors.page.listUsers.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listUsersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.User[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.User) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listUsers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUsers, request)); - }); - - it('invokes listUsersStream with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUsers.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listUsersStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.User[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.User) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listUsers.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listUsers, request)); - }); - - it('uses async iteration with listUsers without error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - generateSampleMessage(new protos.google.showcase.v1beta1.User()), - ]; - client.descriptors.page.listUsers.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IUser[] = []; - const iterable = client.listUsersAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listUsers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listUsers with error', async () => { - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListUsersRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listUsers.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listUsersAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IUser[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listUsers.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new identityModule.v1beta1.IdentityClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_messaging_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_messaging_v1beta1.ts.baseline deleted file mode 100644 index d7b2ff9708e6..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_messaging_v1beta1.ts.baseline +++ /dev/null @@ -1,2356 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as messagingModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubServerStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // write something to the stream to trigger transformStub and send the response back to the client - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - return sinon.stub().returns(mockStream); -} - -function stubBidiStreamingCall(response?: ResponseType, error?: Error) { - const transformStub = error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream); -} - -function stubClientStreamingCall(response?: ResponseType, error?: Error) { - if (error) { - return sinon.stub().callsArgWith(2, error); - } - const transformStub = sinon.stub(); - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - return sinon.stub().returns(mockStream).callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.MessagingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = messagingModule.v1beta1.MessagingClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = messagingModule.v1beta1.MessagingClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new messagingModule.v1beta1.MessagingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = messagingModule.v1beta1.MessagingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new messagingModule.v1beta1.MessagingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new messagingModule.v1beta1.MessagingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.messagingStub, undefined); - await client.initialize(); - assert(client.messagingStub); - }); - - it('has close method for the initialized client', done => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.messagingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.messagingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new messagingModule.v1beta1.MessagingClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new messagingModule.v1beta1.MessagingClient({ - 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); - }); - }); - - describe('createRoom', () => { - it('invokes createRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.createRoom = stubSimpleCall(expectedResponse); - const [response] = await client.createRoom(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.createRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createRoom(request), expectedError); - }); - - it('invokes createRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateRoomRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createRoom(request), expectedError); - }); - }); - - describe('getRoom', () => { - it('invokes getRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.getRoom = stubSimpleCall(expectedResponse); - const [response] = await client.getRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.getRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetRoomRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getRoom(request), expectedError); - }); - }); - - describe('updateRoom', () => { - it('invokes updateRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.updateRoom = stubSimpleCall(expectedResponse); - const [response] = await client.updateRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Room() - ); - client.innerApiCalls.updateRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateRoom( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedHeaderRequestParams = `room.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateRoomRequest() - ); - request.room ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateRoomRequest', ['room', 'name']); - request.room.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateRoom(request), expectedError); - }); - }); - - describe('deleteRoom', () => { - it('invokes deleteRoom without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoom = stubSimpleCall(expectedResponse); - const [response] = await client.deleteRoom(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteRoom = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteRoom( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteRoom = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteRoom(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteRoom as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteRoom with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteRoomRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteRoomRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteRoom(request), expectedError); - }); - }); - - describe('createBlurb', () => { - it('invokes createBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.createBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.createBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.createBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.CreateBlurbRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createBlurb(request), expectedError); - }); - }); - - describe('getBlurb', () => { - it('invokes getBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.getBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.getBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.getBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getBlurb(request), expectedError); - }); - }); - - describe('updateBlurb', () => { - it('invokes updateBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.updateBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.updateBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Blurb() - ); - client.innerApiCalls.updateBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateBlurb( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedHeaderRequestParams = `blurb.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.UpdateBlurbRequest() - ); - request.blurb ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.UpdateBlurbRequest', ['blurb', 'name']); - request.blurb.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateBlurb(request), expectedError); - }); - }); - - describe('deleteBlurb', () => { - it('invokes deleteBlurb without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBlurb = stubSimpleCall(expectedResponse); - const [response] = await client.deleteBlurb(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteBlurb = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteBlurb( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteBlurb = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteBlurb(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteBlurb as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteBlurb with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteBlurbRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteBlurbRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteBlurb(request), expectedError); - }); - }); - - describe('searchBlurbs', () => { - it('invokes searchBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(expectedResponse); - const [operation] = await client.searchBlurbs(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.searchBlurbs = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.searchBlurbs( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs with call error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.searchBlurbs(request), expectedError); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes searchBlurbs with LRO error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.SearchBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.SearchBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.searchBlurbs = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.searchBlurbs(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.searchBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkSearchBlurbsProgress without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkSearchBlurbsProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkSearchBlurbsProgress with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkSearchBlurbsProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('streamBlurbs', () => { - it('invokes streamBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs without error and gaxServerStreamingRetries enabled', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - gaxServerStreamingRetries: true - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.streamBlurbs = stubServerStreamingCall(undefined, expectedError); - const stream = client.streamBlurbs(request); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes streamBlurbs with closed client', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - const stream = client.streamBlurbs(request, {retryRequestOptions: {noResponseRetries: 0}}); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - }); - it('should create a client with gaxServerStreamingRetries enabled', () => { - const client = new messagingModule.v1beta1.MessagingClient({ - gaxServerStreamingRetries: true, - }); - assert(client); - }); - }); - - describe('connect', () => { - it('invokes connect without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ConnectRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.StreamBlurbsResponse() - ); - client.innerApiCalls.connect = stubBidiStreamingCall(expectedResponse); - const stream = client.connect(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.connect as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes connect with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ConnectRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.connect = stubBidiStreamingCall(undefined, expectedError); - const stream = client.connect(); - const promise = new Promise((resolve, reject) => { - stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => { - resolve(response); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.connect as SinonStub) - .getCall(0).calledWith(null)); - assert.deepStrictEqual(((stream as unknown as PassThrough) - ._transform as SinonStub).getCall(0).args[0], request); - }); - }); - - describe('sendBlurbs', () => { - it('invokes sendBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SendBlurbsResponse() - ); - client.innerApiCalls.sendBlurbs = stubClientStreamingCall(expectedResponse); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.sendBlurbs( - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISendBlurbsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.sendBlurbs as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - assert.deepStrictEqual((stream!._transform as SinonStub).getCall(0).args[0], request); - }); - - it('invokes sendBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateBlurbRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.sendBlurbs = stubClientStreamingCall(undefined, expectedError); - let stream: PassThrough; - const promise = new Promise((resolve, reject) => { - stream = client.sendBlurbs( - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISendBlurbsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }) as unknown as PassThrough; - stream.write(request); - stream.end(); - }); - await assert.rejects(promise, expectedError); - assert((client.innerApiCalls.sendBlurbs as SinonStub) - .getCall(0).calledWith(null, {} /*, callback defined above */)); - }); - }); - - describe('listRooms', () => { - it('invokes listRooms without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.innerApiCalls.listRooms = stubSimpleCall(expectedResponse); - const [response] = await client.listRooms(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listRooms without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.innerApiCalls.listRooms = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listRooms( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IRoom[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listRooms with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listRooms = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listRooms(request), expectedError); - }); - - it('invokes listRoomsStream without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.descriptors.page.listRooms.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listRoomsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Room[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Room) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listRooms.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRooms, request)); - }); - - it('invokes listRoomsStream with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listRooms.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listRoomsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Room[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Room) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listRooms.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listRooms, request)); - }); - - it('uses async iteration with listRooms without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - generateSampleMessage(new protos.google.showcase.v1beta1.Room()), - ]; - client.descriptors.page.listRooms.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IRoom[] = []; - const iterable = client.listRoomsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRooms.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listRooms with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListRoomsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listRooms.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listRoomsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IRoom[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRooms.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listBlurbs', () => { - it('invokes listBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.innerApiCalls.listBlurbs = stubSimpleCall(expectedResponse); - const [response] = await client.listBlurbs(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbs without error using callback', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.innerApiCalls.listBlurbs = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listBlurbs( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IBlurb[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listBlurbs = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listBlurbs(request), expectedError); - const actualRequest = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listBlurbs as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listBlurbsStream without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.descriptors.page.listBlurbs.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listBlurbsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Blurb[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Blurb) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBlurbs, request)); - assert( - (client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listBlurbsStream with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBlurbs.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listBlurbsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Blurb[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Blurb) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listBlurbs, request)); - assert( - (client.descriptors.page.listBlurbs.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBlurbs without error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - generateSampleMessage(new protos.google.showcase.v1beta1.Blurb()), - ]; - client.descriptors.page.listBlurbs.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.IBlurb[] = []; - const iterable = client.listBlurbsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listBlurbs with error', async () => { - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListBlurbsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListBlurbsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listBlurbs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listBlurbsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.IBlurb[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listBlurbs.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new messagingModule.v1beta1.MessagingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_sequence_service_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_sequence_service_v1beta1.ts.baseline deleted file mode 100644 index e772cf81a761..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_sequence_service_v1beta1.ts.baseline +++ /dev/null @@ -1,869 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as sequenceserviceModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1beta1.SequenceServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = sequenceserviceModule.v1beta1.SequenceServiceClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = sequenceserviceModule.v1beta1.SequenceServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new sequenceserviceModule.v1beta1.SequenceServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = sequenceserviceModule.v1beta1.SequenceServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sequenceServiceStub, undefined); - await client.initialize(); - assert(client.sequenceServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.sequenceServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.sequenceServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - 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); - }); - }); - - describe('createSequence', () => { - it('invokes createSequence without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Sequence() - ); - client.innerApiCalls.createSequence = stubSimpleCall(expectedResponse); - const [response] = await client.createSequence(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSequence without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Sequence() - ); - client.innerApiCalls.createSequence = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSequence( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISequence|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSequence with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createSequence = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSequence(request), expectedError); - }); - - it('invokes createSequence with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSequenceRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSequence(request), expectedError); - }); - }); - - describe('getSequenceReport', () => { - it('invokes getSequenceReport without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SequenceReport() - ); - client.innerApiCalls.getSequenceReport = stubSimpleCall(expectedResponse); - const [response] = await client.getSequenceReport(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.SequenceReport() - ); - client.innerApiCalls.getSequenceReport = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSequenceReport( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISequenceReport|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSequenceReport = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSequenceReport(request), expectedError); - const actualRequest = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSequenceReport as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSequenceReport with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSequenceReportRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSequenceReportRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSequenceReport(request), expectedError); - }); - }); - - describe('attemptSequence', () => { - it('invokes attemptSequence without error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.attemptSequence = stubSimpleCall(expectedResponse); - const [response] = await client.attemptSequence(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence without error using callback', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.attemptSequence = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.attemptSequence( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence with error', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.attemptSequence = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.attemptSequence(request), expectedError); - const actualRequest = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.attemptSequence as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes attemptSequence with closed client', async () => { - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.AttemptSequenceRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.AttemptSequenceRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.attemptSequence(request), expectedError); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new sequenceserviceModule.v1beta1.SequenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_testing_v1beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_testing_v1beta1.ts.baseline deleted file mode 100644 index 55e55cff9e27..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/showcase/test/gapic_testing_v1beta1.ts.baseline +++ /dev/null @@ -1,1660 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as testingModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v1beta1.TestingClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new testingModule.v1beta1.TestingClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - }); - - it('has universeDomain', () => { - const client = new testingModule.v1beta1.TestingClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = testingModule.v1beta1.TestingClient.servicePath; - assert.strictEqual(servicePath, 'localhost'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = testingModule.v1beta1.TestingClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'localhost'); - assert(stub.called); - stub.restore(); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new testingModule.v1beta1.TestingClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = testingModule.v1beta1.TestingClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new testingModule.v1beta1.TestingClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new testingModule.v1beta1.TestingClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testingStub, undefined); - await client.initialize(); - assert(client.testingStub); - }); - - it('has close method for the initialized client', done => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.testingStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.testingStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testingModule.v1beta1.TestingClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new testingModule.v1beta1.TestingClient({ - 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); - }); - }); - - describe('createSession', () => { - it('invokes createSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.createSession = stubSimpleCall(expectedResponse); - const [response] = await client.createSession(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.createSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes createSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.createSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createSession(request), expectedError); - }); - - it('invokes createSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.CreateSessionRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createSession(request), expectedError); - }); - }); - - describe('getSession', () => { - it('invokes getSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.getSession = stubSimpleCall(expectedResponse); - const [response] = await client.getSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.Session() - ); - client.innerApiCalls.getSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSession(request), expectedError); - const actualRequest = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.GetSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.GetSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSession(request), expectedError); - }); - }); - - describe('deleteSession', () => { - it('invokes deleteSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSession = stubSimpleCall(expectedResponse); - const [response] = await client.deleteSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteSession( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteSession(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteSession(request), expectedError); - }); - }); - - describe('reportSession', () => { - it('invokes reportSession without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionResponse() - ); - client.innerApiCalls.reportSession = stubSimpleCall(expectedResponse); - const [response] = await client.reportSession(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionResponse() - ); - client.innerApiCalls.reportSession = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.reportSession( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IReportSessionResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.reportSession = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.reportSession(request), expectedError); - const actualRequest = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.reportSession as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes reportSession with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ReportSessionRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ReportSessionRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.reportSession(request), expectedError); - }); - }); - - describe('deleteTest', () => { - it('invokes deleteTest without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTest = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTest(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTest = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTest( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTest = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTest(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTest with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.DeleteTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.DeleteTestRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteTest(request), expectedError); - }); - }); - - describe('verifyTest', () => { - it('invokes verifyTest without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestResponse() - ); - client.innerApiCalls.verifyTest = stubSimpleCall(expectedResponse); - const [response] = await client.verifyTest(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestResponse() - ); - client.innerApiCalls.verifyTest = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.verifyTest( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.IVerifyTestResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.verifyTest = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.verifyTest(request), expectedError); - const actualRequest = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.verifyTest as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes verifyTest with closed client', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.VerifyTestRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.VerifyTestRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.verifyTest(request), expectedError); - }); - }); - - describe('listSessions', () => { - it('invokes listSessions without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.innerApiCalls.listSessions = stubSimpleCall(expectedResponse); - const [response] = await client.listSessions(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listSessions without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - );const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.innerApiCalls.listSessions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listSessions( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ISession[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listSessions with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listSessions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listSessions(request), expectedError); - }); - - it('invokes listSessionsStream without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.descriptors.page.listSessions.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listSessionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Session[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Session) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listSessions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSessions, request)); - }); - - it('invokes listSessionsStream with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listSessions.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listSessionsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Session[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Session) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listSessions.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listSessions, request)); - }); - - it('uses async iteration with listSessions without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - generateSampleMessage(new protos.google.showcase.v1beta1.Session()), - ]; - client.descriptors.page.listSessions.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.ISession[] = []; - const iterable = client.listSessionsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listSessions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - - it('uses async iteration with listSessions with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListSessionsRequest() - ); - const expectedError = new Error('expected'); - client.descriptors.page.listSessions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listSessionsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.ISession[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listSessions.asyncIterate as SinonStub) - .getCall(0).args[1], request); - }); - }); - - describe('listTests', () => { - it('invokes listTests without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.innerApiCalls.listTests = stubSimpleCall(expectedResponse); - const [response] = await client.listTests(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTests without error using callback', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.innerApiCalls.listTests = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTests( - request, - (err?: Error|null, result?: protos.google.showcase.v1beta1.ITest[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTests with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTests = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTests(request), expectedError); - const actualRequest = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTests as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTestsStream without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.descriptors.page.listTests.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTestsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Test[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Test) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTests, request)); - assert( - (client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTestsStream with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTests.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTestsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.showcase.v1beta1.Test[] = []; - stream.on('data', (response: protos.google.showcase.v1beta1.Test) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTests, request)); - assert( - (client.descriptors.page.listTests.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTests without error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - generateSampleMessage(new protos.google.showcase.v1beta1.Test()), - ]; - client.descriptors.page.listTests.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.showcase.v1beta1.ITest[] = []; - const iterable = client.listTestsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTests with error', async () => { - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.showcase.v1beta1.ListTestsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.showcase.v1beta1.ListTestsRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTests.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTestsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.showcase.v1beta1.ITest[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTests.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('blueprint', async () => { - const fakePath = "/rendered/path/blueprint"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - blueprint: "blueprintValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.blueprintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.blueprintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('blueprintPath', () => { - const result = client.blueprintPath("sessionValue", "testValue", "blueprintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.blueprintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromBlueprintName', () => { - const result = client.matchSessionFromBlueprintName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromBlueprintName', () => { - const result = client.matchTestFromBlueprintName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlueprintFromBlueprintName', () => { - const result = client.matchBlueprintFromBlueprintName(fakePath); - assert.strictEqual(result, "blueprintValue"); - assert((client.pathTemplates.blueprintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('room', async () => { - const fakePath = "/rendered/path/room"; - const expectedParameters = { - room: "roomValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomPath', () => { - const result = client.roomPath("roomValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomName', () => { - const result = client.matchRoomFromRoomName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurb"; - const expectedParameters = { - room: "roomValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbPath', () => { - const result = client.roomBlurbPath("roomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('roomBlurbsLegacyRoomBlurb', async () => { - const fakePath = "/rendered/path/roomBlurbsLegacyRoomBlurb"; - const expectedParameters = { - room: "roomValue", - legacy_room: "legacyRoomValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('roomBlurbsLegacyRoomBlurbPath', () => { - const result = client.roomBlurbsLegacyRoomBlurbPath("roomValue", "legacyRoomValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "roomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchLegacyRoomFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "legacyRoomValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromRoomBlurbsLegacyRoomBlurbName', () => { - const result = client.matchBlurbFromRoomBlurbsLegacyRoomBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.roomBlurbsLegacyRoomBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequence', async () => { - const fakePath = "/rendered/path/sequence"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequencePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequencePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequencePath', () => { - const result = client.sequencePath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequencePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceName', () => { - const result = client.matchSequenceFromSequenceName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequencePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('sequenceReport', async () => { - const fakePath = "/rendered/path/sequenceReport"; - const expectedParameters = { - sequence: "sequenceValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sequenceReportPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sequenceReportPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sequenceReportPath', () => { - const result = client.sequenceReportPath("sequenceValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sequenceReportPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSequenceFromSequenceReportName', () => { - const result = client.matchSequenceFromSequenceReportName(fakePath); - assert.strictEqual(result, "sequenceValue"); - assert((client.pathTemplates.sequenceReportPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('session', async () => { - const fakePath = "/rendered/path/session"; - const expectedParameters = { - session: "sessionValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.sessionPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.sessionPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('sessionPath', () => { - const result = client.sessionPath("sessionValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.sessionPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromSessionName', () => { - const result = client.matchSessionFromSessionName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.sessionPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('test', async () => { - const fakePath = "/rendered/path/test"; - const expectedParameters = { - session: "sessionValue", - test: "testValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.testPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.testPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('testPath', () => { - const result = client.testPath("sessionValue", "testValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.testPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchSessionFromTestName', () => { - const result = client.matchSessionFromTestName(fakePath); - assert.strictEqual(result, "sessionValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTestFromTestName', () => { - const result = client.matchTestFromTestName(fakePath); - assert.strictEqual(result, "testValue"); - assert((client.pathTemplates.testPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('user', async () => { - const fakePath = "/rendered/path/user"; - const expectedParameters = { - user: "userValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userPath', () => { - const result = client.userPath("userValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserName', () => { - const result = client.matchUserFromUserName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurb"; - const expectedParameters = { - user: "userValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbPath', () => { - const result = client.userProfileBlurbPath("userValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('userProfileBlurbsLegacyUserBlurb', async () => { - const fakePath = "/rendered/path/userProfileBlurbsLegacyUserBlurb"; - const expectedParameters = { - user: "userValue", - legacy_user: "legacyUserValue", - blurb: "blurbValue", - }; - const client = new testingModule.v1beta1.TestingClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('userProfileBlurbsLegacyUserBlurbPath', () => { - const result = client.userProfileBlurbsLegacyUserBlurbPath("userValue", "legacyUserValue", "blurbValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "userValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchLegacyUserFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "legacyUserValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchBlurbFromUserProfileBlurbsLegacyUserBlurbName', () => { - const result = client.matchBlurbFromUserProfileBlurbsLegacyUserBlurbName(fakePath); - assert.strictEqual(result, "blurbValue"); - assert((client.pathTemplates.userProfileBlurbsLegacyUserBlurbPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/showcase/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/showcase/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/showcase/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/showcase/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/tasks-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/tasks-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index af88f8121ce6..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const tasks = require('tasks'); - -function main() { - const cloudTasksClient = new tasks.CloudTasksClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 6aec0f5af462..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as tasks from 'tasks'; - -function main() { - const cloudTasksClient = new tasks.CloudTasksClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index ec89e07d98c8..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {CloudTasksClient} from 'tasks'; - -// check that the client class type name can be used -function doStuffWithCloudTasksClient(client: CloudTasksClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const cloudTasksClient = new CloudTasksClient(); - doStuffWithCloudTasksClient(cloudTasksClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/test/gapic_cloud_tasks_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/test/gapic_cloud_tasks_v2.ts.baseline deleted file mode 100644 index c5117b2279a0..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/esm/test/gapic_cloud_tasks_v2.ts.baseline +++ /dev/null @@ -1,2379 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as cloudtasksModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.CloudTasksClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new cloudtasksModule.v2.CloudTasksClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudtasks.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new cloudtasksModule.v2.CloudTasksClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = cloudtasksModule.v2.CloudTasksClient.servicePath; - assert.strictEqual(servicePath, 'cloudtasks.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = cloudtasksModule.v2.CloudTasksClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudtasks.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new cloudtasksModule.v2.CloudTasksClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudtasks.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new cloudtasksModule.v2.CloudTasksClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudtasks.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new cloudtasksModule.v2.CloudTasksClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudtasks.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new cloudtasksModule.v2.CloudTasksClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudtasks.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new cloudtasksModule.v2.CloudTasksClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = cloudtasksModule.v2.CloudTasksClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new cloudtasksModule.v2.CloudTasksClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudTasksStub, undefined); - await client.initialize(); - assert(client.cloudTasksStub); - }); - - it('has close method for the initialized client', done => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.cloudTasksStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudTasksStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudtasksModule.v2.CloudTasksClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudtasksModule.v2.CloudTasksClient({ - 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); - }); - }); - - describe('getQueue', () => { - it('invokes getQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.getQueue = stubSimpleCall(expectedResponse); - const [response] = await client.getQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.getQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getQueue(request), expectedError); - }); - }); - - describe('createQueue', () => { - it('invokes createQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateQueueRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.createQueue = stubSimpleCall(expectedResponse); - const [response] = await client.createQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateQueueRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.createQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateQueueRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateQueueRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createQueue(request), expectedError); - }); - }); - - describe('updateQueue', () => { - it('invokes updateQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.UpdateQueueRequest() - ); - request.queue ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.UpdateQueueRequest', ['queue', 'name']); - request.queue.name = defaultValue1; - const expectedHeaderRequestParams = `queue.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.updateQueue = stubSimpleCall(expectedResponse); - const [response] = await client.updateQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.UpdateQueueRequest() - ); - request.queue ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.UpdateQueueRequest', ['queue', 'name']); - request.queue.name = defaultValue1; - const expectedHeaderRequestParams = `queue.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.updateQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.UpdateQueueRequest() - ); - request.queue ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.UpdateQueueRequest', ['queue', 'name']); - request.queue.name = defaultValue1; - const expectedHeaderRequestParams = `queue.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.UpdateQueueRequest() - ); - request.queue ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.UpdateQueueRequest', ['queue', 'name']); - request.queue.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateQueue(request), expectedError); - }); - }); - - describe('deleteQueue', () => { - it('invokes deleteQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteQueue = stubSimpleCall(expectedResponse); - const [response] = await client.deleteQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteQueue( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteQueue(request), expectedError); - }); - }); - - describe('purgeQueue', () => { - it('invokes purgeQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PurgeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PurgeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.purgeQueue = stubSimpleCall(expectedResponse); - const [response] = await client.purgeQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PurgeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PurgeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.purgeQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.purgeQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PurgeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PurgeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.purgeQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PurgeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PurgeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.purgeQueue(request), expectedError); - }); - }); - - describe('pauseQueue', () => { - it('invokes pauseQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PauseQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PauseQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.pauseQueue = stubSimpleCall(expectedResponse); - const [response] = await client.pauseQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PauseQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PauseQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.pauseQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pauseQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PauseQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PauseQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.pauseQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pauseQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PauseQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PauseQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pauseQueue(request), expectedError); - }); - }); - - describe('resumeQueue', () => { - it('invokes resumeQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ResumeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ResumeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.resumeQueue = stubSimpleCall(expectedResponse); - const [response] = await client.resumeQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ResumeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ResumeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.resumeQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resumeQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ResumeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ResumeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.resumeQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.resumeQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ResumeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ResumeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.resumeQueue(request), expectedError); - }); - }); - - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.getIamPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.getIamPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.getIamPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIamPolicy( - request, - (err?: Error|null, result?: protos.google.iam.v1.IPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getIamPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getIamPolicy(request), expectedError); - }); - }); - - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.setIamPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.setIamPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.setIamPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setIamPolicy( - request, - (err?: Error|null, result?: protos.google.iam.v1.IPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.setIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setIamPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.setIamPolicy(request), expectedError); - }); - }); - - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsResponse() - ); - client.innerApiCalls.testIamPermissions = stubSimpleCall(expectedResponse); - const [response] = await client.testIamPermissions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsResponse() - ); - client.innerApiCalls.testIamPermissions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.testIamPermissions( - request, - (err?: Error|null, result?: protos.google.iam.v1.ITestIamPermissionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.testIamPermissions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.testIamPermissions(request), expectedError); - const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.testIamPermissions(request), expectedError); - }); - }); - - describe('getTask', () => { - it('invokes getTask without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.getTask = stubSimpleCall(expectedResponse); - const [response] = await client.getTask(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTask without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.getTask = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getTask( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.ITask|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTask with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getTask = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getTask(request), expectedError); - const actualRequest = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTask with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetTaskRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getTask(request), expectedError); - }); - }); - - describe('createTask', () => { - it('invokes createTask without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateTaskRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.createTask = stubSimpleCall(expectedResponse); - const [response] = await client.createTask(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTask without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateTaskRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.createTask = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createTask( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.ITask|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTask with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateTaskRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createTask = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createTask(request), expectedError); - const actualRequest = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTask with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateTaskRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createTask(request), expectedError); - }); - }); - - describe('deleteTask', () => { - it('invokes deleteTask without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTask = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTask(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTask without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTask = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTask( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTask with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTask = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTask(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTask with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteTaskRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteTask(request), expectedError); - }); - }); - - describe('runTask', () => { - it('invokes runTask without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.RunTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.RunTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.runTask = stubSimpleCall(expectedResponse); - const [response] = await client.runTask(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runTask without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.RunTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.RunTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.runTask = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.runTask( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.ITask|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runTask with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.RunTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.RunTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.runTask = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.runTask(request), expectedError); - const actualRequest = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runTask with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.RunTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.RunTaskRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.runTask(request), expectedError); - }); - }); - - describe('listQueues', () => { - it('invokes listQueues without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - ]; - client.innerApiCalls.listQueues = stubSimpleCall(expectedResponse); - const [response] = await client.listQueues(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listQueues without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - ]; - client.innerApiCalls.listQueues = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listQueues( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listQueues with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listQueues = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listQueues(request), expectedError); - const actualRequest = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listQueuesStream without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - ]; - client.descriptors.page.listQueues.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listQueuesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.tasks.v2.Queue[] = []; - stream.on('data', (response: protos.google.cloud.tasks.v2.Queue) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listQueues.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listQueues, request)); - assert( - (client.descriptors.page.listQueues.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listQueuesStream with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listQueues.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listQueuesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.tasks.v2.Queue[] = []; - stream.on('data', (response: protos.google.cloud.tasks.v2.Queue) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listQueues.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listQueues, request)); - assert( - (client.descriptors.page.listQueues.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listQueues without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - ]; - client.descriptors.page.listQueues.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.tasks.v2.IQueue[] = []; - const iterable = client.listQueuesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listQueues.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listQueues.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listQueues with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listQueues.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listQueuesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.tasks.v2.IQueue[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listQueues.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listQueues.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listTasks', () => { - it('invokes listTasks without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - ]; - client.innerApiCalls.listTasks = stubSimpleCall(expectedResponse); - const [response] = await client.listTasks(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTasks without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - ]; - client.innerApiCalls.listTasks = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTasks( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.ITask[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTasks with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTasks = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTasks(request), expectedError); - const actualRequest = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTasksStream without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - ]; - client.descriptors.page.listTasks.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTasksStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.tasks.v2.Task[] = []; - stream.on('data', (response: protos.google.cloud.tasks.v2.Task) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTasks.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTasks, request)); - assert( - (client.descriptors.page.listTasks.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTasksStream with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTasks.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTasksStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.tasks.v2.Task[] = []; - stream.on('data', (response: protos.google.cloud.tasks.v2.Task) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTasks.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTasks, request)); - assert( - (client.descriptors.page.listTasks.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTasks without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - ]; - client.descriptors.page.listTasks.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.tasks.v2.ITask[] = []; - const iterable = client.listTasksAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTasks.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTasks.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTasks with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTasks.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTasksAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.tasks.v2.ITask[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTasks.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTasks.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('queue', () => { - const fakePath = "/rendered/path/queue"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - queue: "queueValue", - }; - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.queuePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.queuePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('queuePath', () => { - const result = client.queuePath("projectValue", "locationValue", "queueValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.queuePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromQueueName', () => { - const result = client.matchProjectFromQueueName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.queuePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromQueueName', () => { - const result = client.matchLocationFromQueueName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.queuePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchQueueFromQueueName', () => { - const result = client.matchQueueFromQueueName(fakePath); - assert.strictEqual(result, "queueValue"); - assert((client.pathTemplates.queuePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('task', () => { - const fakePath = "/rendered/path/task"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - queue: "queueValue", - task: "taskValue", - }; - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.taskPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.taskPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('taskPath', () => { - const result = client.taskPath("projectValue", "locationValue", "queueValue", "taskValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.taskPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromTaskName', () => { - const result = client.matchProjectFromTaskName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.taskPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromTaskName', () => { - const result = client.matchLocationFromTaskName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.taskPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchQueueFromTaskName', () => { - const result = client.matchQueueFromTaskName(fakePath); - assert.strictEqual(result, "queueValue"); - assert((client.pathTemplates.taskPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTaskFromTaskName', () => { - const result = client.matchTaskFromTaskName(fakePath); - assert.strictEqual(result, "taskValue"); - assert((client.pathTemplates.taskPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/package.json b/core/generator/gapic-generator-typescript/baselines/tasks-esm/package.json index 6d4ca6260b1f..1368fbce8012 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/tasks-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/tasks-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/tasks-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/tasks-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/tasks-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/tasks/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/tasks/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/package.json b/core/generator/gapic-generator-typescript/baselines/tasks/package.json index 2717514a26d4..6d722d91f059 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks/package.json +++ b/core/generator/gapic-generator-typescript/baselines/tasks/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 1312a0b8f56d..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const tasks = require('tasks'); - -function main() { - const cloudTasksClient = new tasks.CloudTasksClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index df887c5a29f4..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {CloudTasksClient} from 'tasks'; - -// check that the client class type name can be used -function doStuffWithCloudTasksClient(client: CloudTasksClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const cloudTasksClient = new CloudTasksClient(); - doStuffWithCloudTasksClient(cloudTasksClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/test/gapic_cloud_tasks_v2.ts.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/test/gapic_cloud_tasks_v2.ts.baseline deleted file mode 100644 index 1adb1dd2c4c0..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/tasks/test/gapic_cloud_tasks_v2.ts.baseline +++ /dev/null @@ -1,2370 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as cloudtasksModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.CloudTasksClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new cloudtasksModule.v2.CloudTasksClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudtasks.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new cloudtasksModule.v2.CloudTasksClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = cloudtasksModule.v2.CloudTasksClient.servicePath; - assert.strictEqual(servicePath, 'cloudtasks.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = cloudtasksModule.v2.CloudTasksClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'cloudtasks.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new cloudtasksModule.v2.CloudTasksClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudtasks.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new cloudtasksModule.v2.CloudTasksClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudtasks.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new cloudtasksModule.v2.CloudTasksClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudtasks.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new cloudtasksModule.v2.CloudTasksClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'cloudtasks.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new cloudtasksModule.v2.CloudTasksClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = cloudtasksModule.v2.CloudTasksClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new cloudtasksModule.v2.CloudTasksClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudTasksStub, undefined); - await client.initialize(); - assert(client.cloudTasksStub); - }); - - it('has close method for the initialized client', done => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.cloudTasksStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.cloudTasksStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudtasksModule.v2.CloudTasksClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new cloudtasksModule.v2.CloudTasksClient({ - 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); - }); - }); - - describe('getQueue', () => { - it('invokes getQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.getQueue = stubSimpleCall(expectedResponse); - const [response] = await client.getQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.getQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getQueue(request), expectedError); - }); - }); - - describe('createQueue', () => { - it('invokes createQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateQueueRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.createQueue = stubSimpleCall(expectedResponse); - const [response] = await client.createQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateQueueRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.createQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateQueueRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateQueueRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createQueue(request), expectedError); - }); - }); - - describe('updateQueue', () => { - it('invokes updateQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.UpdateQueueRequest() - ); - request.queue ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.UpdateQueueRequest', ['queue', 'name']); - request.queue.name = defaultValue1; - const expectedHeaderRequestParams = `queue.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.updateQueue = stubSimpleCall(expectedResponse); - const [response] = await client.updateQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.UpdateQueueRequest() - ); - request.queue ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.UpdateQueueRequest', ['queue', 'name']); - request.queue.name = defaultValue1; - const expectedHeaderRequestParams = `queue.name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.updateQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updateQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.UpdateQueueRequest() - ); - request.queue ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.UpdateQueueRequest', ['queue', 'name']); - request.queue.name = defaultValue1; - const expectedHeaderRequestParams = `queue.name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.updateQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updateQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.updateQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes updateQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.UpdateQueueRequest() - ); - request.queue ??= {}; - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.UpdateQueueRequest', ['queue', 'name']); - request.queue.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.updateQueue(request), expectedError); - }); - }); - - describe('deleteQueue', () => { - it('invokes deleteQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteQueue = stubSimpleCall(expectedResponse); - const [response] = await client.deleteQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteQueue( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteQueue(request), expectedError); - }); - }); - - describe('purgeQueue', () => { - it('invokes purgeQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PurgeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PurgeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.purgeQueue = stubSimpleCall(expectedResponse); - const [response] = await client.purgeQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PurgeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PurgeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.purgeQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.purgeQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PurgeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PurgeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.purgeQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.purgeQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.purgeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes purgeQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PurgeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PurgeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.purgeQueue(request), expectedError); - }); - }); - - describe('pauseQueue', () => { - it('invokes pauseQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PauseQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PauseQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.pauseQueue = stubSimpleCall(expectedResponse); - const [response] = await client.pauseQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PauseQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PauseQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.pauseQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.pauseQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PauseQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PauseQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.pauseQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.pauseQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.pauseQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes pauseQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.PauseQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.PauseQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.pauseQueue(request), expectedError); - }); - }); - - describe('resumeQueue', () => { - it('invokes resumeQueue without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ResumeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ResumeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.resumeQueue = stubSimpleCall(expectedResponse); - const [response] = await client.resumeQueue(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeQueue without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ResumeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ResumeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Queue() - ); - client.innerApiCalls.resumeQueue = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.resumeQueue( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeQueue with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ResumeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ResumeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.resumeQueue = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.resumeQueue(request), expectedError); - const actualRequest = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.resumeQueue as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes resumeQueue with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ResumeQueueRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ResumeQueueRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.resumeQueue(request), expectedError); - }); - }); - - describe('getIamPolicy', () => { - it('invokes getIamPolicy without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.getIamPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.getIamPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.getIamPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getIamPolicy( - request, - (err?: Error|null, result?: protos.google.iam.v1.IPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getIamPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getIamPolicy with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.GetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.GetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getIamPolicy(request), expectedError); - }); - }); - - describe('setIamPolicy', () => { - it('invokes setIamPolicy without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.setIamPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.setIamPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.Policy() - ); - client.innerApiCalls.setIamPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.setIamPolicy( - request, - (err?: Error|null, result?: protos.google.iam.v1.IPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.setIamPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.setIamPolicy(request), expectedError); - const actualRequest = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.setIamPolicy as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes setIamPolicy with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.SetIamPolicyRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.SetIamPolicyRequest', ['resource']); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.setIamPolicy(request), expectedError); - }); - }); - - describe('testIamPermissions', () => { - it('invokes testIamPermissions without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsResponse() - ); - client.innerApiCalls.testIamPermissions = stubSimpleCall(expectedResponse); - const [response] = await client.testIamPermissions(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsResponse() - ); - client.innerApiCalls.testIamPermissions = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.testIamPermissions( - request, - (err?: Error|null, result?: protos.google.iam.v1.ITestIamPermissionsResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); - request.resource = defaultValue1; - const expectedHeaderRequestParams = `resource=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.testIamPermissions = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.testIamPermissions(request), expectedError); - const actualRequest = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.testIamPermissions as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes testIamPermissions with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.iam.v1.TestIamPermissionsRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.iam.v1.TestIamPermissionsRequest', ['resource']); - request.resource = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.testIamPermissions(request), expectedError); - }); - }); - - describe('getTask', () => { - it('invokes getTask without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.getTask = stubSimpleCall(expectedResponse); - const [response] = await client.getTask(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTask without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.getTask = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getTask( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.ITask|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTask with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getTask = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getTask(request), expectedError); - const actualRequest = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getTask with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.GetTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.GetTaskRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getTask(request), expectedError); - }); - }); - - describe('createTask', () => { - it('invokes createTask without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateTaskRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.createTask = stubSimpleCall(expectedResponse); - const [response] = await client.createTask(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTask without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateTaskRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.createTask = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createTask( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.ITask|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTask with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateTaskRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createTask = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createTask(request), expectedError); - const actualRequest = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createTask with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.CreateTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.CreateTaskRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.createTask(request), expectedError); - }); - }); - - describe('deleteTask', () => { - it('invokes deleteTask without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTask = stubSimpleCall(expectedResponse); - const [response] = await client.deleteTask(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTask without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.protobuf.Empty() - ); - client.innerApiCalls.deleteTask = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteTask( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTask with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteTask = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deleteTask(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteTask with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.DeleteTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.DeleteTaskRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.deleteTask(request), expectedError); - }); - }); - - describe('runTask', () => { - it('invokes runTask without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.RunTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.RunTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.runTask = stubSimpleCall(expectedResponse); - const [response] = await client.runTask(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runTask without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.RunTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.RunTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.tasks.v2.Task() - ); - client.innerApiCalls.runTask = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.runTask( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.ITask|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runTask with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.RunTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.RunTaskRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.runTask = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.runTask(request), expectedError); - const actualRequest = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.runTask as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes runTask with closed client', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.RunTaskRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.RunTaskRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.runTask(request), expectedError); - }); - }); - - describe('listQueues', () => { - it('invokes listQueues without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - ]; - client.innerApiCalls.listQueues = stubSimpleCall(expectedResponse); - const [response] = await client.listQueues(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listQueues without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - ]; - client.innerApiCalls.listQueues = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listQueues( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.IQueue[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listQueues with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listQueues = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listQueues(request), expectedError); - const actualRequest = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listQueues as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listQueuesStream without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - ]; - client.descriptors.page.listQueues.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listQueuesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.tasks.v2.Queue[] = []; - stream.on('data', (response: protos.google.cloud.tasks.v2.Queue) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listQueues.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listQueues, request)); - assert( - (client.descriptors.page.listQueues.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listQueuesStream with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listQueues.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listQueuesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.tasks.v2.Queue[] = []; - stream.on('data', (response: protos.google.cloud.tasks.v2.Queue) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listQueues.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listQueues, request)); - assert( - (client.descriptors.page.listQueues.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listQueues without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Queue()), - ]; - client.descriptors.page.listQueues.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.tasks.v2.IQueue[] = []; - const iterable = client.listQueuesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listQueues.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listQueues.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listQueues with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListQueuesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListQueuesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listQueues.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listQueuesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.tasks.v2.IQueue[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listQueues.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listQueues.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('listTasks', () => { - it('invokes listTasks without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - ]; - client.innerApiCalls.listTasks = stubSimpleCall(expectedResponse); - const [response] = await client.listTasks(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTasks without error using callback', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - ]; - client.innerApiCalls.listTasks = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listTasks( - request, - (err?: Error|null, result?: protos.google.cloud.tasks.v2.ITask[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTasks with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listTasks = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listTasks(request), expectedError); - const actualRequest = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listTasks as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listTasksStream without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - ]; - client.descriptors.page.listTasks.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listTasksStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.tasks.v2.Task[] = []; - stream.on('data', (response: protos.google.cloud.tasks.v2.Task) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listTasks.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTasks, request)); - assert( - (client.descriptors.page.listTasks.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listTasksStream with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTasks.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listTasksStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.tasks.v2.Task[] = []; - stream.on('data', (response: protos.google.cloud.tasks.v2.Task) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listTasks.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listTasks, request)); - assert( - (client.descriptors.page.listTasks.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTasks without error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - generateSampleMessage(new protos.google.cloud.tasks.v2.Task()), - ]; - client.descriptors.page.listTasks.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.tasks.v2.ITask[] = []; - const iterable = client.listTasksAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listTasks.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTasks.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listTasks with error', async () => { - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.tasks.v2.ListTasksRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.tasks.v2.ListTasksRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listTasks.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listTasksAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.tasks.v2.ITask[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listTasks.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listTasks.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('queue', async () => { - const fakePath = "/rendered/path/queue"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - queue: "queueValue", - }; - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.queuePathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.queuePathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('queuePath', () => { - const result = client.queuePath("projectValue", "locationValue", "queueValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.queuePathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromQueueName', () => { - const result = client.matchProjectFromQueueName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.queuePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromQueueName', () => { - const result = client.matchLocationFromQueueName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.queuePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchQueueFromQueueName', () => { - const result = client.matchQueueFromQueueName(fakePath); - assert.strictEqual(result, "queueValue"); - assert((client.pathTemplates.queuePathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('task', async () => { - const fakePath = "/rendered/path/task"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - queue: "queueValue", - task: "taskValue", - }; - const client = new cloudtasksModule.v2.CloudTasksClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.taskPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.taskPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('taskPath', () => { - const result = client.taskPath("projectValue", "locationValue", "queueValue", "taskValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.taskPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromTaskName', () => { - const result = client.matchProjectFromTaskName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.taskPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromTaskName', () => { - const result = client.matchLocationFromTaskName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.taskPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchQueueFromTaskName', () => { - const result = client.matchQueueFromTaskName(fakePath); - assert.strictEqual(result, "queueValue"); - assert((client.pathTemplates.taskPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchTaskFromTaskName', () => { - const result = client.matchTaskFromTaskName(fakePath); - assert.strictEqual(result, "taskValue"); - assert((client.pathTemplates.taskPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/tasks/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/tasks/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/tasks/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/tasks/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 4c8c03c15aa7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const texttospeech = require('@google-cloud/text-to-speech'); - -function main() { - const textToSpeechClient = new texttospeech.TextToSpeechClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index a399ed4be589..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as texttospeech from '@google-cloud/text-to-speech'; - -function main() { - const textToSpeechClient = new texttospeech.TextToSpeechClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 74618c48da6c..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {TextToSpeechClient} from '@google-cloud/text-to-speech'; - -// check that the client class type name can be used -function doStuffWithTextToSpeechClient(client: TextToSpeechClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const textToSpeechClient = new TextToSpeechClient(); - doStuffWithTextToSpeechClient(textToSpeechClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/test/gapic_text_to_speech_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/test/gapic_text_to_speech_v1.ts.baseline deleted file mode 100644 index 58e28b8f3b9f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/esm/test/gapic_text_to_speech_v1.ts.baseline +++ /dev/null @@ -1,373 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as texttospeechModule from '../src/index.js'; - -import {protobuf} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1.TextToSpeechClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new texttospeechModule.v1.TextToSpeechClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'texttospeech.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new texttospeechModule.v1.TextToSpeechClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = texttospeechModule.v1.TextToSpeechClient.servicePath; - assert.strictEqual(servicePath, 'texttospeech.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = texttospeechModule.v1.TextToSpeechClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'texttospeech.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new texttospeechModule.v1.TextToSpeechClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'texttospeech.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new texttospeechModule.v1.TextToSpeechClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'texttospeech.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new texttospeechModule.v1.TextToSpeechClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'texttospeech.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new texttospeechModule.v1.TextToSpeechClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'texttospeech.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new texttospeechModule.v1.TextToSpeechClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = texttospeechModule.v1.TextToSpeechClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new texttospeechModule.v1.TextToSpeechClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.textToSpeechStub, undefined); - await client.initialize(); - assert(client.textToSpeechStub); - }); - - it('has close method for the initialized client', done => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.textToSpeechStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.textToSpeechStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new texttospeechModule.v1.TextToSpeechClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new texttospeechModule.v1.TextToSpeechClient({ - 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); - }); - }); - - describe('listVoices', () => { - it('invokes listVoices without error', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesResponse() - ); - client.innerApiCalls.listVoices = stubSimpleCall(expectedResponse); - const [response] = await client.listVoices(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listVoices without error using callback', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesResponse() - ); - client.innerApiCalls.listVoices = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listVoices( - request, - (err?: Error|null, result?: protos.google.cloud.texttospeech.v1.IListVoicesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listVoices with error', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listVoices = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listVoices(request), expectedError); - }); - - it('invokes listVoices with closed client', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listVoices(request), expectedError); - }); - }); - - describe('synthesizeSpeech', () => { - it('invokes synthesizeSpeech without error', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechResponse() - ); - client.innerApiCalls.synthesizeSpeech = stubSimpleCall(expectedResponse); - const [response] = await client.synthesizeSpeech(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes synthesizeSpeech without error using callback', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechResponse() - ); - client.innerApiCalls.synthesizeSpeech = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.synthesizeSpeech( - request, - (err?: Error|null, result?: protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes synthesizeSpeech with error', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.synthesizeSpeech = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.synthesizeSpeech(request), expectedError); - }); - - it('invokes synthesizeSpeech with closed client', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.synthesizeSpeech(request), expectedError); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/package.json b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/package.json index 7acefc2a563d..a0a9e5259a66 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/package.json b/core/generator/gapic-generator-typescript/baselines/texttospeech/package.json index 07f6bb0a393b..988d4f5293f8 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/package.json +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 2292e3b2911f..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const texttospeech = require('@google-cloud/text-to-speech'); - -function main() { - const textToSpeechClient = new texttospeech.TextToSpeechClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 71b0bcb6738b..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {TextToSpeechClient} from '@google-cloud/text-to-speech'; - -// check that the client class type name can be used -function doStuffWithTextToSpeechClient(client: TextToSpeechClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const textToSpeechClient = new TextToSpeechClient(); - doStuffWithTextToSpeechClient(textToSpeechClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/test/gapic_text_to_speech_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/test/gapic_text_to_speech_v1.ts.baseline deleted file mode 100644 index e9a7f7455ce7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/test/gapic_text_to_speech_v1.ts.baseline +++ /dev/null @@ -1,364 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as texttospeechModule from '../src'; - -import {protobuf} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -describe('v1.TextToSpeechClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new texttospeechModule.v1.TextToSpeechClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'texttospeech.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new texttospeechModule.v1.TextToSpeechClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = texttospeechModule.v1.TextToSpeechClient.servicePath; - assert.strictEqual(servicePath, 'texttospeech.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = texttospeechModule.v1.TextToSpeechClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'texttospeech.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new texttospeechModule.v1.TextToSpeechClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'texttospeech.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new texttospeechModule.v1.TextToSpeechClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'texttospeech.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new texttospeechModule.v1.TextToSpeechClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'texttospeech.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new texttospeechModule.v1.TextToSpeechClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'texttospeech.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new texttospeechModule.v1.TextToSpeechClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = texttospeechModule.v1.TextToSpeechClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new texttospeechModule.v1.TextToSpeechClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.textToSpeechStub, undefined); - await client.initialize(); - assert(client.textToSpeechStub); - }); - - it('has close method for the initialized client', done => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.textToSpeechStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.textToSpeechStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new texttospeechModule.v1.TextToSpeechClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new texttospeechModule.v1.TextToSpeechClient({ - 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); - }); - }); - - describe('listVoices', () => { - it('invokes listVoices without error', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesResponse() - ); - client.innerApiCalls.listVoices = stubSimpleCall(expectedResponse); - const [response] = await client.listVoices(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listVoices without error using callback', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesResponse() - ); - client.innerApiCalls.listVoices = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listVoices( - request, - (err?: Error|null, result?: protos.google.cloud.texttospeech.v1.IListVoicesResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes listVoices with error', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.listVoices = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listVoices(request), expectedError); - }); - - it('invokes listVoices with closed client', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.ListVoicesRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.listVoices(request), expectedError); - }); - }); - - describe('synthesizeSpeech', () => { - it('invokes synthesizeSpeech without error', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechResponse() - ); - client.innerApiCalls.synthesizeSpeech = stubSimpleCall(expectedResponse); - const [response] = await client.synthesizeSpeech(request); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes synthesizeSpeech without error using callback', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechResponse() - ); - client.innerApiCalls.synthesizeSpeech = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.synthesizeSpeech( - request, - (err?: Error|null, result?: protos.google.cloud.texttospeech.v1.ISynthesizeSpeechResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes synthesizeSpeech with error', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.synthesizeSpeech = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.synthesizeSpeech(request), expectedError); - }); - - it('invokes synthesizeSpeech with closed client', async () => { - const client = new texttospeechModule.v1.TextToSpeechClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.texttospeech.v1.SynthesizeSpeechRequest() - ); - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.synthesizeSpeech(request), expectedError); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/texttospeech/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/texttospeech/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/texttospeech/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/texttospeech/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/translate-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/translate-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index d33945fc8831..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const translation = require('translation'); - -function main() { - const translationServiceClient = new translation.TranslationServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 73b7d3434b75..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as translation from 'translation'; - -function main() { - const translationServiceClient = new translation.TranslationServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 15bd45a8eca7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {TranslationServiceClient} from 'translation'; - -// check that the client class type name can be used -function doStuffWithTranslationServiceClient(client: TranslationServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const translationServiceClient = new TranslationServiceClient(); - doStuffWithTranslationServiceClient(translationServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/test/gapic_translation_service_v3beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/test/gapic_translation_service_v3beta1.ts.baseline deleted file mode 100644 index 629006c0a48b..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/esm/test/gapic_translation_service_v3beta1.ts.baseline +++ /dev/null @@ -1,1512 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as translationserviceModule from '../src/index.js'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3beta1.TranslationServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'translate.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = translationserviceModule.v3beta1.TranslationServiceClient.servicePath; - assert.strictEqual(servicePath, 'translate.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = translationserviceModule.v3beta1.TranslationServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'translate.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'translate.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'translate.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new translationserviceModule.v3beta1.TranslationServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'translate.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'translate.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new translationserviceModule.v3beta1.TranslationServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = translationserviceModule.v3beta1.TranslationServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.translationServiceStub, undefined); - await client.initialize(); - assert(client.translationServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.translationServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.translationServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - 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); - }); - }); - - describe('translateText', () => { - it('invokes translateText without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.TranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextResponse() - ); - client.innerApiCalls.translateText = stubSimpleCall(expectedResponse); - const [response] = await client.translateText(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes translateText without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.TranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextResponse() - ); - client.innerApiCalls.translateText = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.translateText( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.ITranslateTextResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes translateText with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.TranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.translateText = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.translateText(request), expectedError); - const actualRequest = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes translateText with closed client', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.TranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.translateText(request), expectedError); - }); - }); - - describe('detectLanguage', () => { - it('invokes detectLanguage without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DetectLanguageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageResponse() - ); - client.innerApiCalls.detectLanguage = stubSimpleCall(expectedResponse); - const [response] = await client.detectLanguage(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detectLanguage without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DetectLanguageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageResponse() - ); - client.innerApiCalls.detectLanguage = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.detectLanguage( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.IDetectLanguageResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detectLanguage with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DetectLanguageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.detectLanguage = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.detectLanguage(request), expectedError); - const actualRequest = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detectLanguage with closed client', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DetectLanguageRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.detectLanguage(request), expectedError); - }); - }); - - describe('getSupportedLanguages', () => { - it('invokes getSupportedLanguages without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.SupportedLanguages() - ); - client.innerApiCalls.getSupportedLanguages = stubSimpleCall(expectedResponse); - const [response] = await client.getSupportedLanguages(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSupportedLanguages without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.SupportedLanguages() - ); - client.innerApiCalls.getSupportedLanguages = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSupportedLanguages( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.ISupportedLanguages|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSupportedLanguages with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSupportedLanguages = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSupportedLanguages(request), expectedError); - const actualRequest = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSupportedLanguages with closed client', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSupportedLanguages(request), expectedError); - }); - }); - - describe('getGlossary', () => { - it('invokes getGlossary without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.Glossary() - ); - client.innerApiCalls.getGlossary = stubSimpleCall(expectedResponse); - const [response] = await client.getGlossary(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGlossary without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.Glossary() - ); - client.innerApiCalls.getGlossary = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getGlossary( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.IGlossary|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGlossary with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getGlossary = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getGlossary(request), expectedError); - const actualRequest = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGlossary with closed client', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getGlossary(request), expectedError); - }); - }); - - describe('batchTranslateText', () => { - it('invokes batchTranslateText without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.BatchTranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.batchTranslateText = stubLongRunningCall(expectedResponse); - const [operation] = await client.batchTranslateText(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchTranslateText without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.BatchTranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.batchTranslateText = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchTranslateText( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchTranslateText with call error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.BatchTranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchTranslateText = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.batchTranslateText(request), expectedError); - const actualRequest = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchTranslateText with LRO error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.BatchTranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchTranslateText = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.batchTranslateText(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkBatchTranslateTextProgress without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkBatchTranslateTextProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkBatchTranslateTextProgress with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkBatchTranslateTextProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('createGlossary', () => { - it('invokes createGlossary without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.CreateGlossaryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createGlossary = stubLongRunningCall(expectedResponse); - const [operation] = await client.createGlossary(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGlossary without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.CreateGlossaryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createGlossary = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createGlossary( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGlossary with call error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.CreateGlossaryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createGlossary = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.createGlossary(request), expectedError); - const actualRequest = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGlossary with LRO error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.CreateGlossaryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createGlossary = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.createGlossary(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateGlossaryProgress without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateGlossaryProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateGlossaryProgress with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCreateGlossaryProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('deleteGlossary', () => { - it('invokes deleteGlossary without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DeleteGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.deleteGlossary = stubLongRunningCall(expectedResponse); - const [operation] = await client.deleteGlossary(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGlossary without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DeleteGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.deleteGlossary = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteGlossary( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGlossary with call error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DeleteGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteGlossary = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.deleteGlossary(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGlossary with LRO error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DeleteGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteGlossary = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.deleteGlossary(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkDeleteGlossaryProgress without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkDeleteGlossaryProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkDeleteGlossaryProgress with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkDeleteGlossaryProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listGlossaries', () => { - it('invokes listGlossaries without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - ]; - client.innerApiCalls.listGlossaries = stubSimpleCall(expectedResponse); - const [response] = await client.listGlossaries(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGlossaries without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - ]; - client.innerApiCalls.listGlossaries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listGlossaries( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.IGlossary[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGlossaries with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listGlossaries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listGlossaries(request), expectedError); - const actualRequest = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGlossariesStream without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - ]; - client.descriptors.page.listGlossaries.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listGlossariesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.translation.v3beta1.Glossary[] = []; - stream.on('data', (response: protos.google.cloud.translation.v3beta1.Glossary) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listGlossaries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGlossaries, request)); - assert( - (client.descriptors.page.listGlossaries.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listGlossariesStream with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGlossaries.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listGlossariesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.translation.v3beta1.Glossary[] = []; - stream.on('data', (response: protos.google.cloud.translation.v3beta1.Glossary) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listGlossaries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGlossaries, request)); - assert( - (client.descriptors.page.listGlossaries.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGlossaries without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - ]; - client.descriptors.page.listGlossaries.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.translation.v3beta1.IGlossary[] = []; - const iterable = client.listGlossariesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGlossaries with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGlossaries.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listGlossariesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.translation.v3beta1.IGlossary[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('glossary', () => { - const fakePath = "/rendered/path/glossary"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - glossary: "glossaryValue", - }; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.glossaryPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.glossaryPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('glossaryPath', () => { - const result = client.glossaryPath("projectValue", "locationValue", "glossaryValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.glossaryPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromGlossaryName', () => { - const result = client.matchProjectFromGlossaryName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.glossaryPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromGlossaryName', () => { - const result = client.matchLocationFromGlossaryName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.glossaryPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGlossaryFromGlossaryName', () => { - const result = client.matchGlossaryFromGlossaryName(fakePath); - assert.strictEqual(result, "glossaryValue"); - assert((client.pathTemplates.glossaryPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('location', () => { - const fakePath = "/rendered/path/location"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - }; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - client.pathTemplates.locationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.locationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath("projectValue", "locationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/package.json b/core/generator/gapic-generator-typescript/baselines/translate-esm/package.json index 5df9b5f36163..ec102c647152 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/translate-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/translate-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/translate-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/translate-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/translate-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/translate/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/translate/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/translate/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/translate/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/translate/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/translate/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/translate/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/translate/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/translate/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/translate/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/translate/package.json b/core/generator/gapic-generator-typescript/baselines/translate/package.json index e04f1dc2d7bd..1174ceb75e90 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate/package.json +++ b/core/generator/gapic-generator-typescript/baselines/translate/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/translate/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/translate/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 6c68622980f6..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const translation = require('translation'); - -function main() { - const translationServiceClient = new translation.TranslationServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/translate/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/translate/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 06dcee3e6811..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {TranslationServiceClient} from 'translation'; - -// check that the client class type name can be used -function doStuffWithTranslationServiceClient(client: TranslationServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const translationServiceClient = new TranslationServiceClient(); - doStuffWithTranslationServiceClient(translationServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/translate/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/translate/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/translate/test/gapic_translation_service_v3beta1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/translate/test/gapic_translation_service_v3beta1.ts.baseline deleted file mode 100644 index de19cb3fb570..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/translate/test/gapic_translation_service_v3beta1.ts.baseline +++ /dev/null @@ -1,1503 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as translationserviceModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v3beta1.TranslationServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'translate.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = translationserviceModule.v3beta1.TranslationServiceClient.servicePath; - assert.strictEqual(servicePath, 'translate.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = translationserviceModule.v3beta1.TranslationServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'translate.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'translate.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'translate.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new translationserviceModule.v3beta1.TranslationServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'translate.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'translate.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new translationserviceModule.v3beta1.TranslationServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = translationserviceModule.v3beta1.TranslationServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.translationServiceStub, undefined); - await client.initialize(); - assert(client.translationServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.translationServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.translationServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - 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); - }); - }); - - describe('translateText', () => { - it('invokes translateText without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.TranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextResponse() - ); - client.innerApiCalls.translateText = stubSimpleCall(expectedResponse); - const [response] = await client.translateText(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes translateText without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.TranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextResponse() - ); - client.innerApiCalls.translateText = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.translateText( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.ITranslateTextResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes translateText with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.TranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.translateText = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.translateText(request), expectedError); - const actualRequest = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.translateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes translateText with closed client', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.TranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.TranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.translateText(request), expectedError); - }); - }); - - describe('detectLanguage', () => { - it('invokes detectLanguage without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DetectLanguageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageResponse() - ); - client.innerApiCalls.detectLanguage = stubSimpleCall(expectedResponse); - const [response] = await client.detectLanguage(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detectLanguage without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DetectLanguageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageResponse() - ); - client.innerApiCalls.detectLanguage = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.detectLanguage( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.IDetectLanguageResponse|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detectLanguage with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DetectLanguageRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.detectLanguage = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.detectLanguage(request), expectedError); - const actualRequest = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes detectLanguage with closed client', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DetectLanguageRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.detectLanguage(request), expectedError); - }); - }); - - describe('getSupportedLanguages', () => { - it('invokes getSupportedLanguages without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.SupportedLanguages() - ); - client.innerApiCalls.getSupportedLanguages = stubSimpleCall(expectedResponse); - const [response] = await client.getSupportedLanguages(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSupportedLanguages without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.SupportedLanguages() - ); - client.innerApiCalls.getSupportedLanguages = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getSupportedLanguages( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.ISupportedLanguages|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSupportedLanguages with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getSupportedLanguages = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getSupportedLanguages(request), expectedError); - const actualRequest = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getSupportedLanguages with closed client', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', ['parent']); - request.parent = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getSupportedLanguages(request), expectedError); - }); - }); - - describe('getGlossary', () => { - it('invokes getGlossary without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.Glossary() - ); - client.innerApiCalls.getGlossary = stubSimpleCall(expectedResponse); - const [response] = await client.getGlossary(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGlossary without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.Glossary() - ); - client.innerApiCalls.getGlossary = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getGlossary( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.IGlossary|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGlossary with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.getGlossary = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getGlossary(request), expectedError); - const actualRequest = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes getGlossary with closed client', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.GetGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedError = new Error('The client has already been closed.'); - client.close().catch(err => {throw err}); - await assert.rejects(client.getGlossary(request), expectedError); - }); - }); - - describe('batchTranslateText', () => { - it('invokes batchTranslateText without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.BatchTranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.batchTranslateText = stubLongRunningCall(expectedResponse); - const [operation] = await client.batchTranslateText(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchTranslateText without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.BatchTranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.batchTranslateText = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.batchTranslateText( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchTranslateText with call error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.BatchTranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchTranslateText = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.batchTranslateText(request), expectedError); - const actualRequest = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes batchTranslateText with LRO error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.BatchTranslateTextRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.batchTranslateText = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.batchTranslateText(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkBatchTranslateTextProgress without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkBatchTranslateTextProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkBatchTranslateTextProgress with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkBatchTranslateTextProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('createGlossary', () => { - it('invokes createGlossary without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.CreateGlossaryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createGlossary = stubLongRunningCall(expectedResponse); - const [operation] = await client.createGlossary(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGlossary without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.CreateGlossaryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.createGlossary = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createGlossary( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGlossary with call error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.CreateGlossaryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createGlossary = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.createGlossary(request), expectedError); - const actualRequest = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes createGlossary with LRO error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.CreateGlossaryRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.createGlossary = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.createGlossary(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkCreateGlossaryProgress without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkCreateGlossaryProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkCreateGlossaryProgress with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkCreateGlossaryProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('deleteGlossary', () => { - it('invokes deleteGlossary without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DeleteGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.deleteGlossary = stubLongRunningCall(expectedResponse); - const [operation] = await client.deleteGlossary(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGlossary without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DeleteGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.deleteGlossary = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deleteGlossary( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGlossary with call error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DeleteGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteGlossary = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.deleteGlossary(request), expectedError); - const actualRequest = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes deleteGlossary with LRO error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.DeleteGlossaryRequest', ['name']); - request.name = defaultValue1; - const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.deleteGlossary = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.deleteGlossary(request); - await assert.rejects(operation.promise(), expectedError); - const actualRequest = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes checkDeleteGlossaryProgress without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkDeleteGlossaryProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkDeleteGlossaryProgress with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkDeleteGlossaryProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); - - describe('listGlossaries', () => { - it('invokes listGlossaries without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - ]; - client.innerApiCalls.listGlossaries = stubSimpleCall(expectedResponse); - const [response] = await client.listGlossaries(request); - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGlossaries without error using callback', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`;const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - ]; - client.innerApiCalls.listGlossaries = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listGlossaries( - request, - (err?: Error|null, result?: protos.google.cloud.translation.v3beta1.IGlossary[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - const actualRequest = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGlossaries with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.innerApiCalls.listGlossaries = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listGlossaries(request), expectedError); - const actualRequest = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[0]; - assert.deepStrictEqual(actualRequest, request); - const actualHeaderRequestParams = (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0).args[1].otherArgs.headers['x-goog-request-params']; - assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - }); - - it('invokes listGlossariesStream without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - ]; - client.descriptors.page.listGlossaries.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listGlossariesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.translation.v3beta1.Glossary[] = []; - stream.on('data', (response: protos.google.cloud.translation.v3beta1.Glossary) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listGlossaries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGlossaries, request)); - assert( - (client.descriptors.page.listGlossaries.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('invokes listGlossariesStream with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGlossaries.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listGlossariesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.translation.v3beta1.Glossary[] = []; - stream.on('data', (response: protos.google.cloud.translation.v3beta1.Glossary) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listGlossaries.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listGlossaries, request)); - assert( - (client.descriptors.page.listGlossaries.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGlossaries without error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - generateSampleMessage(new protos.google.cloud.translation.v3beta1.Glossary()), - ]; - client.descriptors.page.listGlossaries.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.translation.v3beta1.IGlossary[] = []; - const iterable = client.listGlossariesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - - it('uses async iteration with listGlossaries with error', async () => { - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() - ); - const defaultValue1 = - getTypeDefaultValue('.google.cloud.translation.v3beta1.ListGlossariesRequest', ['parent']); - request.parent = defaultValue1; - const expectedHeaderRequestParams = `parent=${defaultValue1 ?? '' }`; - const expectedError = new Error('expected'); - client.descriptors.page.listGlossaries.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listGlossariesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.translation.v3beta1.IGlossary[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert( - (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'].includes( - expectedHeaderRequestParams - ) - ); - }); - }); - - describe('Path templates', () => { - - describe('glossary', async () => { - const fakePath = "/rendered/path/glossary"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - glossary: "glossaryValue", - }; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.glossaryPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.glossaryPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('glossaryPath', () => { - const result = client.glossaryPath("projectValue", "locationValue", "glossaryValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.glossaryPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromGlossaryName', () => { - const result = client.matchProjectFromGlossaryName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.glossaryPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromGlossaryName', () => { - const result = client.matchLocationFromGlossaryName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.glossaryPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchGlossaryFromGlossaryName', () => { - const result = client.matchGlossaryFromGlossaryName(fakePath); - assert.strictEqual(result, "glossaryValue"); - assert((client.pathTemplates.glossaryPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('location', async () => { - const fakePath = "/rendered/path/location"; - const expectedParameters = { - project: "projectValue", - location: "locationValue", - }; - const client = new translationserviceModule.v3beta1.TranslationServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - client.pathTemplates.locationPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.locationPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('locationPath', () => { - const result = client.locationPath("projectValue", "locationValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.locationPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromLocationName', () => { - const result = client.matchProjectFromLocationName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchLocationFromLocationName', () => { - const result = client.matchLocationFromLocationName(fakePath); - assert.strictEqual(result, "locationValue"); - assert((client.pathTemplates.locationPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/translate/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/translate/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/translate/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/translate/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.eslintignore.baseline index a73044f809ca..b2a989524773 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.eslintignore.baseline @@ -3,9 +3,5 @@ build/ docs/ protos/ -system-test/ samples/ -esm/src/**/*.d.ts -esm/test/**/*.d.ts -esm/system-test/**/*.d.ts -esm/system-test/fixtures/sample/src/*.ts \ No newline at end of file +esm/src/**/*.d.ts \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.gitignore.baseline index b391f5f9cd1a..a9dd0919035f 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.mocharc.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.mocharc.cjs.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.mocharc.cjs.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline deleted file mode 100644 index 9211b853189a..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.cjs.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -const videointelligence = require('videointelligence'); - -function main() { - const videoIntelligenceServiceClient = new videointelligence.VideoIntelligenceServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 398644a543cc..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -import * as videointelligence from 'videointelligence'; - -function main() { - const videoIntelligenceServiceClient = new videointelligence.VideoIntelligenceServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 407f139c34e0..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,33 +0,0 @@ -/* eslint-disable node/no-missing-require, no-unused-vars, no-undef */ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {VideoIntelligenceServiceClient} from 'videointelligence'; - -// check that the client class type name can be used -function doStuffWithVideoIntelligenceServiceClient(client: VideoIntelligenceServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const videoIntelligenceServiceClient = new VideoIntelligenceServiceClient(); - doStuffWithVideoIntelligenceServiceClient(videoIntelligenceServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/install.ts.baseline deleted file mode 100644 index e079c4fa1101..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/system-test/install.ts.baseline +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - it('TypeScript', async function() { - this.timeout(300000); - await packNTest({ - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./esm/system-test/fixtures/sample/src/index.ts').toString() - } - }); - }); - - it('ESM module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using ESM', - esm: readFileSync('./esm/system-test/fixtures/sample/src/index.js').toString(), - }, - }); - }); - - it('CJS module', async function() { - this.timeout(300000); - await packNTest({ - sample: { - description: 'Should be able to import using CJS', - cjs: readFileSync('./esm/system-test/fixtures/sample/src/index.cjs').toString(), - }, - }); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/test/gapic_video_intelligence_service_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/test/gapic_video_intelligence_service_v1.ts.baseline deleted file mode 100644 index 3c1ab593ac37..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/esm/test/gapic_video_intelligence_service_v1.ts.baseline +++ /dev/null @@ -1,349 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -// @ts-ignore -import * as protos from '../../protos/protos.js'; -import assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as videointelligenceserviceModule from '../src/index.js'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; -import fs from 'fs'; -import path from 'path'; -import {fileURLToPath} from 'url'; - -// @ts-ignore -const dirname = path.dirname(fileURLToPath(import.meta.url)); -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON( - JSON.parse( - fs.readFileSync(path.join(dirname, '..', '..', 'protos/protos.json'), 'utf8') - )) - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type?.fields[field]?.resolvedType as protobuf.Type; - } - return type?.fields[fields[fields.length - 1]]?.defaultValue ?? null; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v1.VideoIntelligenceServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'videointelligence.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = videointelligenceserviceModule.v1.VideoIntelligenceServiceClient.servicePath; - assert.strictEqual(servicePath, 'videointelligence.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = videointelligenceserviceModule.v1.VideoIntelligenceServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'videointelligence.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'videointelligence.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'videointelligence.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'videointelligence.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'videointelligence.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = videointelligenceserviceModule.v1.VideoIntelligenceServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - await client.initialize(); - assert(client.videoIntelligenceServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.videoIntelligenceServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - 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); - }); - }); - - describe('annotateVideo', () => { - it('invokes annotateVideo without error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.annotateVideo = stubLongRunningCall(expectedResponse); - const [operation] = await client.annotateVideo(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes annotateVideo without error using callback', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.annotateVideo = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.annotateVideo( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes annotateVideo with call error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.annotateVideo = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.annotateVideo(request), expectedError); - }); - - it('invokes annotateVideo with LRO error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.annotateVideo = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.annotateVideo(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkAnnotateVideoProgress without error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkAnnotateVideoProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkAnnotateVideoProgress with error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkAnnotateVideoProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/package.json b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/package.json index c897e60b4a5e..b2883437c190 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/package.json +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/package.json @@ -60,12 +60,6 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", - "test:cjs": "c8 mocha build/cjs/test", - "test:esm": "c8 mocha build/esm/test", - "test": "npm run test:cjs && npm run test:esm", "compile:esm": "tsc -p ./tsconfig.esm.json && cp -r esm/src/json-helper.cjs build/esm/src/json-helper.cjs", "babel": "babel esm --out-dir build/cjs --ignore \"esm/**/*.d.ts\" --extensions \".ts\" --out-file-extension .cjs --copy-files", "compile:cjs": "tsc -p ./tsconfig.json && npm run babel", @@ -80,21 +74,15 @@ "@babel/core": "^7.28.5", "@babel/preset-env": "^7.28.5", "@babel/preset-typescript": "^7.28.5", - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", "babel-plugin-replace-import-extension": "^1.1.5", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-region-tag": "^4.0.1", "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", - "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", - "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", "webpack-cli": "^6.0.1" diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/tsconfig.esm.json.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/tsconfig.esm.json.baseline index 9ea46f074fa2..38ee8a0aaee0 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/tsconfig.esm.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/tsconfig.esm.json.baseline @@ -17,9 +17,6 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", - "esm/system-test/*.ts", "esm/src/**/*.json", "protos/protos.json", "esm/src/*.cjs" diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/tsconfig.json.baseline index 110f6eccd41b..fd2e00c9359a 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence-esm/tsconfig.json.baseline @@ -21,10 +21,7 @@ "include": [ "esm/src/*.ts", "esm/src/**/*.ts", - "esm/test/*.ts", - "esm/test/**/*.ts", "esm/src/**/*.json", - "esm/system-test/*.ts", "esm/src/*.cjs", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/.eslintignore.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/.eslintignore.baseline index cfc348ec4d11..7a5c61f6ae7f 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/.eslintignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence/.eslintignore.baseline @@ -3,5 +3,4 @@ build/ docs/ protos/ -system-test/ samples/generated/ diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/.gitignore.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/.gitignore.baseline index d4f03a0df2e8..4d1d14e0c962 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/.gitignore.baseline +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence/.gitignore.baseline @@ -6,8 +6,6 @@ /docs/ /out/ /build/ -system-test/secrets.js -system-test/*key.json *.lock .DS_Store package-lock.json diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/.mocharc.js.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/.mocharc.js.baseline deleted file mode 100644 index 5eb34e86c874..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/.mocharc.js.baseline +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/.nycrc.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/.nycrc.baseline deleted file mode 100644 index 81a95fc94b00..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/.nycrc.baseline +++ /dev/null @@ -1,24 +0,0 @@ -{ - "report-dir": "./.coverage", - "reporter": ["text", "lcov"], - "exclude": [ - "**/*-test", - "**/.coverage", - "**/apis", - "**/benchmark", - "**/conformance", - "**/docs", - "**/samples", - "**/scripts", - "**/protos", - "**/test", - "**/*.d.ts", - ".jsdoc.js", - "**/.jsdoc.js", - "karma.conf.js", - "webpack-tests.config.js", - "webpack.config.js" - ], - "exclude-after-remap": false, - "all": true -} \ No newline at end of file diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/package.json b/core/generator/gapic-generator-typescript/baselines/videointelligence/package.json index f80a1458ef48..85b80127a1c6 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/package.json +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence/package.json @@ -30,27 +30,19 @@ "docs": "jsdoc -c .jsdoc.js", "fix": "gts fix", "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" + "prepare": "npm run compile-protos && npm run compile" }, "dependencies": { "google-gax": "^5.1.1-rc.1" }, "devDependencies": { - "@types/mocha": "^10.0.10", "@types/node": "^22.18.12", - "@types/sinon": "^20.0.0", - "c8": "^10.1.3", "gapic-tools": "^1.0.3", "gts": "^6.0.2", "jsdoc": "^4.0.5", "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", - "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", - "typescript": "5.8.3", - "sinon": "^20.0.0" + "typescript": "5.8.3" }, "engines": { "node": ">=v18" diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/fixtures/sample/src/index.js.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/fixtures/sample/src/index.js.baseline deleted file mode 100644 index 97981e6b07e2..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/fixtures/sample/src/index.js.baseline +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const videointelligence = require('videointelligence'); - -function main() { - const videoIntelligenceServiceClient = new videointelligence.VideoIntelligenceServiceClient(); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/fixtures/sample/src/index.ts.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/fixtures/sample/src/index.ts.baseline deleted file mode 100644 index 4b3782f73c52..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/fixtures/sample/src/index.ts.baseline +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {VideoIntelligenceServiceClient} from 'videointelligence'; - -// check that the client class type name can be used -function doStuffWithVideoIntelligenceServiceClient(client: VideoIntelligenceServiceClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const videoIntelligenceServiceClient = new VideoIntelligenceServiceClient(); - doStuffWithVideoIntelligenceServiceClient(videoIntelligenceServiceClient); -} - -main(); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/install.ts.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/install.ts.baseline deleted file mode 100644 index f66069aa3940..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/system-test/install.ts.baseline +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - cjs: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/test/gapic_video_intelligence_service_v1.ts.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/test/gapic_video_intelligence_service_v1.ts.baseline deleted file mode 100644 index 075b669d76a7..000000000000 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/test/gapic_video_intelligence_service_v1.ts.baseline +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright 2026 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import {describe, it} from 'mocha'; -import * as videointelligenceserviceModule from '../src'; - -import {protobuf, LROperation, operationsProtos} from 'google-gax'; - -// Dynamically loaded proto JSON is needed to get the type information -// to fill in default values for request objects -const root = protobuf.Root.fromJSON(require('../protos/protos.json')).resolveAll(); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -function getTypeDefaultValue(typeName: string, fields: string[]) { - let type = root.lookupType(typeName) as protobuf.Type; - for (const field of fields.slice(0, -1)) { - type = type.fields[field]?.resolvedType as protobuf.Type; - } - return type.fields[fields[fields.length - 1]]?.defaultValue; -} - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubLongRunningCall(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().rejects(callError) : sinon.stub().resolves([mockOperation]); -} - -function stubLongRunningCallWithCallback(response?: ResponseType, callError?: Error, lroError?: Error) { - const innerStub = lroError ? sinon.stub().rejects(lroError) : sinon.stub().resolves([response]); - const mockOperation = { - promise: innerStub, - }; - return callError ? sinon.stub().callsArgWith(2, callError) : sinon.stub().callsArgWith(2, null, mockOperation); -} - -describe('v1.VideoIntelligenceServiceClient', () => { - describe('Common methods', () => { - it('has apiEndpoint', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - const apiEndpoint = client.apiEndpoint; - assert.strictEqual(apiEndpoint, 'videointelligence.googleapis.com'); - }); - - it('has universeDomain', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - const universeDomain = client.universeDomain; - assert.strictEqual(universeDomain, "googleapis.com"); - }); - - if (typeof process === 'object' && typeof process.emitWarning === 'function') { - it('throws DeprecationWarning if static servicePath is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const servicePath = videointelligenceserviceModule.v1.VideoIntelligenceServiceClient.servicePath; - assert.strictEqual(servicePath, 'videointelligence.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - - it('throws DeprecationWarning if static apiEndpoint is used', () => { - const stub = sinon.stub(process, 'emitWarning'); - const apiEndpoint = videointelligenceserviceModule.v1.VideoIntelligenceServiceClient.apiEndpoint; - assert.strictEqual(apiEndpoint, 'videointelligence.googleapis.com'); - assert(stub.called); - stub.restore(); - }); - } - it('sets apiEndpoint according to universe domain camelCase', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({universeDomain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'videointelligence.example.com'); - }); - - it('sets apiEndpoint according to universe domain snakeCase', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({universe_domain: 'example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'videointelligence.example.com'); - }); - - if (typeof process === 'object' && 'env' in process) { - describe('GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variable', () => { - it('sets apiEndpoint from environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'videointelligence.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - - it('value configured in code has priority over environment variable', () => { - const saved = process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = 'example.com'; - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({universeDomain: 'configured.example.com'}); - const servicePath = client.apiEndpoint; - assert.strictEqual(servicePath, 'videointelligence.configured.example.com'); - if (saved) { - process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN'] = saved; - } else { - delete process.env['GOOGLE_CLOUD_UNIVERSE_DOMAIN']; - } - }); - }); - } - it('does not allow setting both universeDomain and universe_domain', () => { - assert.throws(() => { new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({universe_domain: 'example.com', universeDomain: 'example.net'}); }); - }); - - it('has port', () => { - const port = videointelligenceserviceModule.v1.VideoIntelligenceServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - await client.initialize(); - assert(client.videoIntelligenceServiceStub); - }); - - it('has close method for the initialized client', done => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize().catch(err => {throw err}); - assert(client.videoIntelligenceServiceStub); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has close method for the non-initialized client', done => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.videoIntelligenceServiceStub, undefined); - client.close().then(() => { - done(); - }).catch(err => {throw err}); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - 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()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - 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); - }); - }); - - describe('annotateVideo', () => { - it('invokes annotateVideo without error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.annotateVideo = stubLongRunningCall(expectedResponse); - const [operation] = await client.annotateVideo(request); - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes annotateVideo without error using callback', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() - ); - const expectedResponse = generateSampleMessage( - new protos.google.longrunning.Operation() - ); - client.innerApiCalls.annotateVideo = stubLongRunningCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.annotateVideo( - request, - (err?: Error|null, - result?: LROperation|null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const operation = await promise as LROperation; - const [response] = await operation.promise(); - assert.deepStrictEqual(response, expectedResponse); - }); - - it('invokes annotateVideo with call error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.annotateVideo = stubLongRunningCall(undefined, expectedError); - await assert.rejects(client.annotateVideo(request), expectedError); - }); - - it('invokes annotateVideo with LRO error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.videointelligence.v1.AnnotateVideoRequest() - ); - const expectedError = new Error('expected'); - client.innerApiCalls.annotateVideo = stubLongRunningCall(undefined, undefined, expectedError); - const [operation] = await client.annotateVideo(request); - await assert.rejects(operation.promise(), expectedError); - }); - - it('invokes checkAnnotateVideoProgress without error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedResponse = generateSampleMessage( - new operationsProtos.google.longrunning.Operation() - ); - expectedResponse.name = 'test'; - expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; - expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')} - - client.operationsClient.getOperation = stubSimpleCall(expectedResponse); - const decodedOperation = await client.checkAnnotateVideoProgress(expectedResponse.name); - assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); - assert(decodedOperation.metadata); - assert((client.operationsClient.getOperation as SinonStub).getCall(0)); - }); - - it('invokes checkAnnotateVideoProgress with error', async () => { - const client = new videointelligenceserviceModule.v1.VideoIntelligenceServiceClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - await client.initialize(); - const expectedError = new Error('expected'); - - client.operationsClient.getOperation = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.checkAnnotateVideoProgress(''), expectedError); - assert((client.operationsClient.getOperation as SinonStub) - .getCall(0)); - }); - }); -}); diff --git a/core/generator/gapic-generator-typescript/baselines/videointelligence/tsconfig.json.baseline b/core/generator/gapic-generator-typescript/baselines/videointelligence/tsconfig.json.baseline index ca73e7bfc824..7c26ffde05a2 100644 --- a/core/generator/gapic-generator-typescript/baselines/videointelligence/tsconfig.json.baseline +++ b/core/generator/gapic-generator-typescript/baselines/videointelligence/tsconfig.json.baseline @@ -12,9 +12,6 @@ "include": [ "src/*.ts", "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts", "src/**/*.json", "samples/**/*.json", "protos/protos.json" diff --git a/core/generator/gapic-generator-typescript/package-lock.json b/core/generator/gapic-generator-typescript/package-lock.json index b9f44aea0416..bda9d2d183c5 100644 --- a/core/generator/gapic-generator-typescript/package-lock.json +++ b/core/generator/gapic-generator-typescript/package-lock.json @@ -48,6 +48,7 @@ "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==", "dev": true, + "license": "Apache-2.0", "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" @@ -61,6 +62,7 @@ "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", "dev": true, + "license": "MIT", "dependencies": { "@babel/helper-validator-identifier": "^7.25.9", "js-tokens": "^4.0.0", @@ -75,6 +77,7 @@ "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.8.tgz", "integrity": "sha512-oH5UPLMWR3L2wEFLnFJ1TZXqHufiTKAiLfqw5zkhS4dKXLJ10yVztfil/twG8EDTA4F/tvVNw9nOl4ZMslB8rQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -84,6 +87,7 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.26.10.tgz", "integrity": "sha512-vMqyb7XCDMPvJFFOaT9kxtiRh42GwlZEg1/uIgtZshS5a/8OaduUfCi7kynKgc3Tw/6Uo2D+db9qBttghhmxwQ==", "dev": true, + "license": "MIT", "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.26.2", @@ -113,13 +117,15 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@babel/generator": { "version": "7.27.0", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.27.0.tgz", "integrity": "sha512-VybsKvpiN1gU1sdMZIp7FcqphVVKEwcuj02x73uvcHE0PTihx1nlBcowYWhDwjpoAXRv43+gDzyggGnn1XZhVw==", "dev": true, + "license": "MIT", "dependencies": { "@babel/parser": "^7.27.0", "@babel/types": "^7.27.0", @@ -136,6 +142,7 @@ "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.27.0.tgz", "integrity": "sha512-LVk7fbXml0H2xH34dFzKQ7TDZ2G4/rVTOrq9V+icbbadjbVxxeFeDsNHv2SrZeWoA+6ZiTyWYWtScEIW07EAcA==", "dev": true, + "license": "MIT", "dependencies": { "@babel/compat-data": "^7.26.8", "@babel/helper-validator-option": "^7.25.9", @@ -152,6 +159,7 @@ "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.25.9.tgz", "integrity": "sha512-tnUA4RsrmflIM6W6RFTLFSXITtl0wKjgpnLgXyowocVPrbYrLUXSBXDgTs8BlbmIzIdlBySRQjINYs2BAkiLtw==", "dev": true, + "license": "MIT", "dependencies": { "@babel/traverse": "^7.25.9", "@babel/types": "^7.25.9" @@ -165,6 +173,7 @@ "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.26.0.tgz", "integrity": "sha512-xO+xu6B5K2czEnQye6BHA7DolFFmS3LB7stHZFaOLb1pAwO1HWLS8fXA+eh0A2yIvltPVmx3eNNDBJA2SLHXFw==", "dev": true, + "license": "MIT", "dependencies": { "@babel/helper-module-imports": "^7.25.9", "@babel/helper-validator-identifier": "^7.25.9", @@ -181,6 +190,7 @@ "version": "7.25.9", "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz", "integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==", + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -189,6 +199,7 @@ "version": "7.25.9", "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -198,6 +209,7 @@ "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.25.9.tgz", "integrity": "sha512-e/zv1co8pp55dNdEcCynfj9X7nyUKUXoUEwfXqaZt0omVOmDe9oOTdKStH4GmAw6zxMFs50ZayuMfHDKlO7Tfw==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -207,6 +219,7 @@ "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.27.0.tgz", "integrity": "sha512-U5eyP/CTFPuNE3qk+WZMxFkp/4zUzdceQlfzf7DdGdhp+Fezd7HD+i8Y24ZuTMKX3wQBld449jijbGq6OdGNQg==", "dev": true, + "license": "MIT", "dependencies": { "@babel/template": "^7.27.0", "@babel/types": "^7.27.0" @@ -219,6 +232,7 @@ "version": "7.27.0", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.0.tgz", "integrity": "sha512-iaepho73/2Pz7w2eMS0Q5f83+0RKI7i4xmiYeBmDzfRVbQtTOG7Ts0S4HzJVsTMGI9keU8rNfuZr8DKfSt7Yyg==", + "license": "MIT", "dependencies": { "@babel/types": "^7.27.0" }, @@ -234,6 +248,7 @@ "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.0.tgz", "integrity": "sha512-2ncevenBqXI6qRMukPlXwHKHchC7RyMuu4xv5JBXRfOGVcTy1mXCD12qrp7Jsoxll1EV3+9sE4GugBVRjT2jFA==", "dev": true, + "license": "MIT", "dependencies": { "@babel/code-frame": "^7.26.2", "@babel/parser": "^7.27.0", @@ -248,6 +263,7 @@ "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.27.0.tgz", "integrity": "sha512-19lYZFzYVQkkHkl4Cy4WrAVcqBkgvV2YM2TU3xG6DIwO7O3ecbDPfW3yM3bjAGcqcQHi+CCtjMR3dIEHxsd6bA==", "dev": true, + "license": "MIT", "dependencies": { "@babel/code-frame": "^7.26.2", "@babel/generator": "^7.27.0", @@ -265,6 +281,7 @@ "version": "7.27.0", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.27.0.tgz", "integrity": "sha512-H45s8fVLYjbhFH62dIJ3WtmJ6RSPt/3DRO0ZcT2SUiYiQyz3BLVb9ADEnLl91m74aQPS3AzzeajZHYOalWe3bg==", + "license": "MIT", "dependencies": { "@babel/helper-string-parser": "^7.25.9", "@babel/helper-validator-identifier": "^7.25.9" @@ -278,6 +295,7 @@ "resolved": "https://registry.npmjs.org/@bazel/bazelisk/-/bazelisk-1.26.0.tgz", "integrity": "sha512-bTNcHdGyEQ9r7SczEYUa0gkEQhJo1ld2BjXI8fWBvsUeoHi03QpUs2HZgDbjjrpQFQqG2ZbO7ihZvH8MjhUTHw==", "dev": true, + "license": "Apache-2.0", "bin": { "bazel": "bazelisk.js", "bazelisk": "bazelisk.js" @@ -288,6 +306,7 @@ "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", "dev": true, + "license": "MIT", "dependencies": { "@jridgewell/trace-mapping": "0.3.9" }, @@ -300,6 +319,7 @@ "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", "dev": true, + "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.0.3", "@jridgewell/sourcemap-codec": "^1.4.10" @@ -310,6 +330,7 @@ "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.6.0.tgz", "integrity": "sha512-WhCn7Z7TauhBtmzhvKpoQs0Wwb/kBcy4CwpuI0/eEIr2Lx2auxmulAzLr91wVZJaz47iUZdkXOK7WlAfxGKCnA==", "dev": true, + "license": "MIT", "dependencies": { "eslint-visitor-keys": "^3.4.3" }, @@ -328,6 +349,7 @@ "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.1.tgz", "integrity": "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ==", "dev": true, + "license": "MIT", "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } @@ -337,6 +359,7 @@ "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", "dev": true, + "license": "MIT", "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", @@ -371,6 +394,7 @@ "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, + "license": "MIT", "dependencies": { "type-fest": "^0.20.2" }, @@ -399,6 +423,7 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true, + "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=10" }, @@ -411,6 +436,7 @@ "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.1.tgz", "integrity": "sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==", "dev": true, + "license": "MIT", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } @@ -420,6 +446,7 @@ "resolved": "https://registry.npmjs.org/@google-cloud/paginator/-/paginator-5.0.2.tgz", "integrity": "sha512-DJS3s0OVH4zFDB1PzjxAsHqJT6sKVbRwwML0ZBP9PbU7Yebtu/7SWMRzvO2J3nUi9pRNITCfu4LJeooM2w4pjg==", "dev": true, + "license": "Apache-2.0", "dependencies": { "arrify": "^2.0.0", "extend": "^3.0.2" @@ -433,6 +460,7 @@ "resolved": "https://registry.npmjs.org/@google-cloud/projectify/-/projectify-4.0.0.tgz", "integrity": "sha512-MmaX6HeSvyPbWGwFq7mXdo0uQZLGBYCwziiLIGq5JVX+/bdI3SAq6bP98trV5eTWfLuvsMcIC1YJOF2vfteLFA==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=14.0.0" } @@ -442,6 +470,7 @@ "resolved": "https://registry.npmjs.org/@google-cloud/promisify/-/promisify-4.0.0.tgz", "integrity": "sha512-Orxzlfb9c67A15cq2JQEyVc7wEsmFBmHjZWZYQMUyJ1qivXyMwdyNOs9odi79hze+2zqdTtu1E19IM/FtqZ10g==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=14" } @@ -478,6 +507,7 @@ "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.13.3.tgz", "integrity": "sha512-FTXHdOoPbZrBjlVLHuKbDZnsTxXv2BlHF57xw6LuThXacXvtkahEPED0CKMk6obZDf65Hv4k3z62eyPNpvinIg==", "dev": true, + "license": "Apache-2.0", "dependencies": { "@grpc/proto-loader": "^0.7.13", "@js-sdsl/ordered-map": "^4.4.2" @@ -491,6 +521,7 @@ "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.7.13.tgz", "integrity": "sha512-AiXO/bfe9bmxBjxxtYxFAXGZvMaN5s8kO+jBHAJCON8rJoB5YS/D6X7ZNc6XQkuHNmyl4CYaMI1fJ/Gn27RGGw==", "dev": true, + "license": "Apache-2.0", "dependencies": { "lodash.camelcase": "^4.3.0", "long": "^5.0.0", @@ -510,6 +541,7 @@ "integrity": "sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==", "deprecated": "Use @eslint/config-array instead", "dev": true, + "license": "Apache-2.0", "dependencies": { "@humanwhocodes/object-schema": "^2.0.3", "debug": "^4.3.1", @@ -548,6 +580,7 @@ "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=12.22" }, @@ -561,13 +594,15 @@ "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", "deprecated": "Use @eslint/object-schema instead", - "dev": true + "dev": true, + "license": "BSD-3-Clause" }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", "dev": true, + "license": "ISC", "dependencies": { "string-width": "^5.1.2", "string-width-cjs": "npm:string-width@^4.2.0", @@ -585,6 +620,7 @@ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", "dev": true, + "license": "MIT", "engines": { "node": ">=12" }, @@ -596,13 +632,15 @@ "version": "9.2.2", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@isaacs/cliui/node_modules/string-width": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", "dev": true, + "license": "MIT", "dependencies": { "eastasianwidth": "^0.2.0", "emoji-regex": "^9.2.2", @@ -620,6 +658,7 @@ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", "dev": true, + "license": "MIT", "dependencies": { "ansi-regex": "^6.0.1" }, @@ -635,6 +674,7 @@ "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.8.tgz", "integrity": "sha512-imAbBGkb+ebQyxKgzv5Hu2nmROxoDOXHh80evxdoXNOrvAnVx7zimzc1Oo5h9RlfV4vPXaE2iM5pOFbvOCClWA==", "dev": true, + "license": "MIT", "dependencies": { "@jridgewell/set-array": "^1.2.1", "@jridgewell/sourcemap-codec": "^1.4.10", @@ -649,6 +689,7 @@ "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.0.0" } @@ -658,6 +699,7 @@ "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.0.0" } @@ -666,13 +708,15 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.25", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", "dev": true, + "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" @@ -683,6 +727,7 @@ "resolved": "https://registry.npmjs.org/@js-sdsl/ordered-map/-/ordered-map-4.4.2.tgz", "integrity": "sha512-iUKgm52T8HOE/makSxjqoWhe95ZJA1/G1sYsGev2JDKUSS14KAgg1LHb+Ba+IPow0xflbnSkOsZcO08C7w1gYw==", "dev": true, + "license": "MIT", "funding": { "type": "opencollective", "url": "https://opencollective.com/js-sdsl" @@ -692,6 +737,7 @@ "version": "0.2.9", "resolved": "https://registry.npmjs.org/@jsdoc/salty/-/salty-0.2.9.tgz", "integrity": "sha512-yYxMVH7Dqw6nO0d5NIV8OQWnitU8k6vXH8NtgqAfIa/IUqRMxRv/NUJJ08VEKbAakwxlgBl5PJdrU0dMPStsnw==", + "license": "Apache-2.0", "dependencies": { "lodash": "^4.17.21" }, @@ -717,6 +763,7 @@ "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" @@ -730,6 +777,7 @@ "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", "dev": true, + "license": "MIT", "engines": { "node": ">= 8" } @@ -739,6 +787,7 @@ "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" @@ -752,6 +801,7 @@ "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz", "integrity": "sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==", "dev": true, + "license": "MIT", "engines": { "node": ">= 18" } @@ -761,6 +811,7 @@ "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.2.2.tgz", "integrity": "sha512-/g2d4sW9nUDJOMz3mabVQvOGhVa4e/BN/Um7yca9Bb2XTzPPnfTWHWQg+IsEYO7M3Vx+EXvaM/I2pJWIMun1bg==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/auth-token": "^4.0.0", "@octokit/graphql": "^7.1.0", @@ -779,6 +830,7 @@ "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.6.tgz", "integrity": "sha512-H1fNTMA57HbkFESSt3Y9+FBICv+0jFceJFPWDePYlR/iMGrwM5ph+Dd4XRQs+8X+PUFURLQgX9ChPfhJ/1uNQw==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/types": "^13.1.0", "universal-user-agent": "^6.0.0" @@ -792,6 +844,7 @@ "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.1.1.tgz", "integrity": "sha512-3mkDltSfcDUoa176nlGoA32RGjeWjl3K7F/BwHwRMJUW/IteSa4bnSV8p2ThNkcIcZU2umkZWxwETSSCJf2Q7g==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/request": "^8.4.1", "@octokit/types": "^13.0.0", @@ -805,13 +858,15 @@ "version": "24.2.0", "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-24.2.0.tgz", "integrity": "sha512-9sIH3nSUttelJSXUrmGzl7QUBFul0/mB8HRYl3fOlgHbIWG+WnYDXU3v/2zMtAvuzZ/ed00Ei6on975FhBfzrg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@octokit/plugin-paginate-rest": { "version": "11.4.4-cjs.2", "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.4.4-cjs.2.tgz", "integrity": "sha512-2dK6z8fhs8lla5PaOTgqfCGBxgAv/le+EhPs27KklPhm1bKObpu6lXzwfUEQ16ajXzqNrKMujsFyo9K2eaoISw==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/types": "^13.7.0" }, @@ -827,6 +882,7 @@ "resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-4.0.1.tgz", "integrity": "sha512-GihNqNpGHorUrO7Qa9JbAl0dbLnqJVrV8OXe2Zm5/Y4wFkZQDfTreBzVmiRfJVfE4mClXdihHnbpyyO9FSX4HA==", "dev": true, + "license": "MIT", "engines": { "node": ">= 18" }, @@ -839,6 +895,7 @@ "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-13.3.2-cjs.1.tgz", "integrity": "sha512-VUjIjOOvF2oELQmiFpWA1aOPdawpyaCUqcEBc/UOUnj3Xp6DJGrJ1+bjUIIDzdHjnFNO6q57ODMfdEZnoBkCwQ==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/types": "^13.8.0" }, @@ -854,6 +911,7 @@ "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.4.1.tgz", "integrity": "sha512-qnB2+SY3hkCmBxZsR/MPCybNmbJe4KAlfWErXq+rBKkQJlbjdJeS85VI9r8UqeLYLvnAenU8Q1okM/0MBsAGXw==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/endpoint": "^9.0.6", "@octokit/request-error": "^5.1.1", @@ -869,6 +927,7 @@ "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.1.1.tgz", "integrity": "sha512-v9iyEQJH6ZntoENr9/yXxjuezh4My67CBSu9r6Ve/05Iu5gNgnisNWOsoJHTP6k0Rr0+HQIpnH+kyammu90q/g==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/types": "^13.1.0", "deprecation": "^2.0.0", @@ -883,6 +942,7 @@ "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-20.1.2.tgz", "integrity": "sha512-GmYiltypkHHtihFwPRxlaorG5R9VAHuk/vbszVoRTGXnAsY60wYLkh/E2XiFmdZmqrisw+9FaazS1i5SbdWYgA==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/core": "^5.0.2", "@octokit/plugin-paginate-rest": "11.4.4-cjs.2", @@ -898,6 +958,7 @@ "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.10.0.tgz", "integrity": "sha512-ifLaO34EbbPj0Xgro4G5lP5asESjwHracYJvVaPIyXMuiuXLlhic3S47cBdTb+jfODkTE5YtGCLt3Ay3+J97sA==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/openapi-types": "^24.2.0" } @@ -907,6 +968,7 @@ "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", "dev": true, + "license": "MIT", "optional": true, "engines": { "node": ">=14" @@ -917,6 +979,7 @@ "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.2.tgz", "integrity": "sha512-fdDH1LSGfZdTH2sxdpVMw31BanV28K/Gry0cVFxaNP77neJSkd82mM8ErPNYs9e+0O7SdHBLTDzDgwUuy18RnQ==", "dev": true, + "license": "MIT", "engines": { "node": "^12.20.0 || ^14.18.0 || >=16.0.0" }, @@ -927,27 +990,32 @@ "node_modules/@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", - "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==" + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==", + "license": "BSD-3-Clause" }, "node_modules/@protobufjs/base64": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", - "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==", + "license": "BSD-3-Clause" }, "node_modules/@protobufjs/codegen": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", - "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" + "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==", + "license": "BSD-3-Clause" }, "node_modules/@protobufjs/eventemitter": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", - "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==" + "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==", + "license": "BSD-3-Clause" }, "node_modules/@protobufjs/fetch": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", "integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==", + "license": "BSD-3-Clause", "dependencies": { "@protobufjs/aspromise": "^1.1.1", "@protobufjs/inquire": "^1.1.0" @@ -956,33 +1024,39 @@ "node_modules/@protobufjs/float": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", - "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==" + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==", + "license": "BSD-3-Clause" }, "node_modules/@protobufjs/inquire": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", - "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==" + "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==", + "license": "BSD-3-Clause" }, "node_modules/@protobufjs/path": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", - "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==" + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==", + "license": "BSD-3-Clause" }, "node_modules/@protobufjs/pool": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", - "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==" + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", + "license": "BSD-3-Clause" }, "node_modules/@protobufjs/utf8": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", - "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" + "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==", + "license": "BSD-3-Clause" }, "node_modules/@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", "dev": true, + "license": "MIT", "engines": { "node": ">= 10" } @@ -991,47 +1065,55 @@ "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@tsconfig/node12": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@tsconfig/node14": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@tsconfig/node16": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/caseless": { "version": "0.12.5", "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.5.tgz", "integrity": "sha512-hWtVTC2q7hc7xZ/RLbxapMvDMgUnDvKvMOpKal4DrMyfGBUfB1oKaZlIRr6mJL+If3bAP6sV/QneGzF6tJjZDg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/js-yaml": { "version": "4.0.9", "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-4.0.9.tgz", - "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==" + "integrity": "sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==", + "license": "MIT" }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/linkify-it": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz", - "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==" + "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==", + "license": "MIT" }, "node_modules/@types/long": { "version": "5.0.0", @@ -1039,6 +1121,7 @@ "integrity": "sha512-eQs9RsucA/LNjnMoJvWG/nXa7Pot/RbBzilF/QRIU/xRl+0ApxrSUFsV5lmf01SvSlqMzJ7Zwxe440wmz2SJGA==", "deprecated": "This is a stub types definition. long provides its own type definitions, so you do not need this installed.", "dev": true, + "license": "MIT", "dependencies": { "long": "*" } @@ -1047,6 +1130,7 @@ "version": "14.1.2", "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz", "integrity": "sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog==", + "license": "MIT", "dependencies": { "@types/linkify-it": "^5", "@types/mdurl": "^2" @@ -1055,25 +1139,29 @@ "node_modules/@types/mdurl": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz", - "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==" + "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==", + "license": "MIT" }, "node_modules/@types/minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.5.tgz", "integrity": "sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/mocha": { "version": "10.0.10", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.10.tgz", "integrity": "sha512-xPyYSz1cMPnJQhl0CLMH68j3gprKZaTjG3s5Vi+fDgx+uhG9NOXwbVt52eFS8ECyXhyKcjDLCBEqBExKuiZb7Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/module-alias": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@types/module-alias/-/module-alias-2.0.4.tgz", "integrity": "sha512-5+G/QXO/DvHZw60FjvbDzO4JmlD/nG5m2/vVGt25VN1eeP3w2bCoks1Wa7VuptMPM1TxJdx6RjO70N9Fw0nZPA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/node": { "version": "22.18.12", @@ -1088,25 +1176,29 @@ "version": "2.4.4", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz", "integrity": "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/nunjucks": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/@types/nunjucks/-/nunjucks-3.2.6.tgz", "integrity": "sha512-pHiGtf83na1nCzliuAdq8GowYiXvH5l931xZ0YEHaLMNFgynpEqx+IPStlu7UaDkehfvl01e4x/9Tpwhy7Ue3w==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/object-hash": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/@types/object-hash/-/object-hash-3.0.6.tgz", "integrity": "sha512-fOBV8C1FIu2ELinoILQ+ApxcUKz4ngq+IWUYrxSGjXzzjUALijilampwkMgEtJ+h2njAW3pi853QpzNVCHB73w==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/request": { "version": "2.48.12", "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.12.tgz", "integrity": "sha512-G3sY+NpsA9jnwm0ixhAFQSJ3Q9JkpLZpJbI3GMv0mIAT0y3mRabYeINzal5WOChIiaTEGQYlHOKgkaM9EisWHw==", "dev": true, + "license": "MIT", "dependencies": { "@types/caseless": "*", "@types/node": "*", @@ -1118,13 +1210,15 @@ "version": "7.7.0", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.7.0.tgz", "integrity": "sha512-k107IF4+Xr7UHjwDc7Cfd6PRQfbdkiRabXGRjo07b4WyPahFBZCZ1sE+BNxYIJPPg73UkfOsVOLwqVc/6ETrIA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/tough-cookie": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", "integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/yargs": { "version": "17.0.34", @@ -1140,13 +1234,15 @@ "version": "21.0.3", "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz", "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "5.62.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.62.0.tgz", "integrity": "sha512-TiZzBSJja/LbhNPvk6yc0JrX9XqhQ0hdh6M2svYfsHGejaKFIAGd9MQ+ERIMzLGlN/kZoYIgdxFV0PuljTKXag==", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.4.0", "@typescript-eslint/scope-manager": "5.62.0", @@ -1181,6 +1277,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -1193,6 +1290,7 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.62.0.tgz", "integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "@typescript-eslint/scope-manager": "5.62.0", "@typescript-eslint/types": "5.62.0", @@ -1220,6 +1318,7 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz", "integrity": "sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w==", "dev": true, + "license": "MIT", "dependencies": { "@typescript-eslint/types": "5.62.0", "@typescript-eslint/visitor-keys": "5.62.0" @@ -1237,6 +1336,7 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.62.0.tgz", "integrity": "sha512-xsSQreu+VnfbqQpW5vnCJdq1Z3Q0U31qiWmRhr98ONQmcp/yhiPJFPq8MXiJVLiksmOKSjIldZzkebzHuCGzew==", "dev": true, + "license": "MIT", "dependencies": { "@typescript-eslint/typescript-estree": "5.62.0", "@typescript-eslint/utils": "5.62.0", @@ -1264,6 +1364,7 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.62.0.tgz", "integrity": "sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==", "dev": true, + "license": "MIT", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -1277,6 +1378,7 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz", "integrity": "sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "@typescript-eslint/types": "5.62.0", "@typescript-eslint/visitor-keys": "5.62.0", @@ -1304,6 +1406,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -1316,6 +1419,7 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", "integrity": "sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@types/json-schema": "^7.0.9", @@ -1342,6 +1446,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -1354,6 +1459,7 @@ "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz", "integrity": "sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw==", "dev": true, + "license": "MIT", "dependencies": { "@typescript-eslint/types": "5.62.0", "eslint-visitor-keys": "^3.3.0" @@ -1370,19 +1476,22 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.0.tgz", "integrity": "sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/a-sync-waterfall": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/a-sync-waterfall/-/a-sync-waterfall-1.0.1.tgz", "integrity": "sha512-RYTOHHdWipFUliRFMCS4X2Yn2X8M87V/OpSqWzKKOGhzqyUxzyVmhHDH9sAvG+ZuQf/TAOFsLCpMw09I1ufUnA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/abort-controller": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", "dev": true, + "license": "MIT", "dependencies": { "event-target-shim": "^5.0.0" }, @@ -1395,6 +1504,7 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz", "integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg==", "dev": true, + "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -1406,13 +1516,15 @@ "version": "1.1.7", "resolved": "https://registry.npmjs.org/acorn-es7-plugin/-/acorn-es7-plugin-1.1.7.tgz", "integrity": "sha512-7D+8kscFMf6F2t+8ZRYmv82CncDZETsaZ4dEl5lh3qQez7FVABk2Vz616SAbnIq1PbNsLVaZjl2oSkk5BWAKng==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/acorn-walk": { "version": "8.3.4", "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", "dev": true, + "license": "MIT", "dependencies": { "acorn": "^8.11.0" }, @@ -1425,6 +1537,7 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz", "integrity": "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg==", "dev": true, + "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -1437,6 +1550,7 @@ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", "integrity": "sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw==", "dev": true, + "license": "MIT", "engines": { "node": ">= 14" } @@ -1446,6 +1560,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, + "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -1462,6 +1577,7 @@ "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", "integrity": "sha512-S2Hw0TtNkMJhIabBwIojKL9YHO5T0n5eNqWJ7Lrlel/zDbftQpxpapi8tZs3X1HWa+u+QeydGmzzNU0m09+Rcg==", "dev": true, + "license": "BSD-3-Clause OR MIT", "engines": { "node": ">=0.4.2" } @@ -1471,6 +1587,7 @@ "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", "integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==", "dev": true, + "license": "MIT", "dependencies": { "type-fest": "^0.21.3" }, @@ -1485,6 +1602,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", "engines": { "node": ">=8" } @@ -1493,6 +1611,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "license": "MIT", "dependencies": { "color-convert": "^2.0.1" }, @@ -1503,28 +1622,48 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "license": "ISC", + "optional": true, + "peer": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "license": "Python-2.0" }, "node_modules/array-find": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/array-find/-/array-find-1.0.0.tgz", "integrity": "sha512-kO/vVCacW9mnpn3WPWbTVlEnOabK2L7LWi2HViURtCM46y1zb6I8UMjx4LgbiqadTgHnLInUronwn3ampNTJtQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/array-union": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -1534,6 +1673,7 @@ "resolved": "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz", "integrity": "sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -1542,13 +1682,15 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/async-retry": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/async-retry/-/async-retry-1.3.3.tgz", "integrity": "sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw==", "dev": true, + "license": "MIT", "dependencies": { "retry": "0.13.1" } @@ -1557,12 +1699,14 @@ "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "license": "MIT" }, "node_modules/base64-js": { "version": "1.5.1", @@ -1582,27 +1726,46 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "MIT" }, "node_modules/before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", - "dev": true + "dev": true, + "license": "Apache-2.0" }, "node_modules/bignumber.js": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.3.0.tgz", "integrity": "sha512-EM7aMFTXbptt/wZdMlBv2t8IViwQL+h6SLHosp8Yf0dqJMTnY6iL32opnAB6kAdL0SZPuvcAzFr31o0c/R3/RA==", "dev": true, + "license": "MIT", "engines": { "node": "*" } }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", - "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", + "license": "MIT" }, "node_modules/brace-expansion": { "version": "2.0.3", @@ -1618,6 +1781,7 @@ "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, + "license": "MIT", "dependencies": { "fill-range": "^7.1.1" }, @@ -1629,7 +1793,8 @@ "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/browserslist": { "version": "4.24.4", @@ -1650,6 +1815,7 @@ "url": "https://github.com/sponsors/ai" } ], + "license": "MIT", "dependencies": { "caniuse-lite": "^1.0.30001688", "electron-to-chromium": "^1.5.73", @@ -1674,13 +1840,15 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/builtins": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/builtins/-/builtins-5.1.0.tgz", "integrity": "sha512-SW9lzGTLvWTP1AY8xeAMZimqDrIaSdLQUcVr9DMef51niJ022Ri87SwRRKYm4A6iHfkPaiVUu/Duw2Wc4J7kKg==", "dev": true, + "license": "MIT", "dependencies": { "semver": "^7.0.0" } @@ -1690,6 +1858,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -1702,6 +1871,7 @@ "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.8.tgz", "integrity": "sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww==", "dev": true, + "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.0", "es-define-property": "^1.0.0", @@ -1720,6 +1890,7 @@ "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", "dev": true, + "license": "MIT", "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2" @@ -1733,6 +1904,7 @@ "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", "dev": true, + "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", "get-intrinsic": "^1.3.0" @@ -1749,6 +1921,7 @@ "resolved": "https://registry.npmjs.org/call-matcher/-/call-matcher-1.1.0.tgz", "integrity": "sha512-IoQLeNwwf9KTNbtSA7aEBb1yfDbdnzwjCetjkC8io5oGeOmK2CBNdg0xr+tadRYKO0p7uQyZzvon0kXlZbvGrw==", "dev": true, + "license": "MIT", "dependencies": { "core-js": "^2.0.0", "deep-equal": "^1.0.0", @@ -1761,6 +1934,7 @@ "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -1770,6 +1944,7 @@ "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -1779,6 +1954,7 @@ "resolved": "https://registry.npmjs.org/camelcase-keys/-/camelcase-keys-6.2.2.tgz", "integrity": "sha512-YrwaA0vEKazPBkn0ipTiMpSajYDSe+KjQfrjhcBMxJt/znbvlHd8Pw/Vamaz5EB4Wfhs3SUR3Z9mwRu/P3s3Yg==", "dev": true, + "license": "MIT", "dependencies": { "camelcase": "^5.3.1", "map-obj": "^4.0.0", @@ -1809,12 +1985,14 @@ "type": "github", "url": "https://github.com/sponsors/ai" } - ] + ], + "license": "CC-BY-4.0" }, "node_modules/catharsis": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.9.0.tgz", "integrity": "sha512-prMTQVpcns/tzFgFVkVp6ak6RykZyWb3gu8ckUpd6YkTlacOd3DXGJjIpD4Q6zJirizvaiAjSSHlOsA+6sNh2A==", + "license": "MIT", "dependencies": { "lodash": "^4.17.15" }, @@ -1826,6 +2004,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "license": "MIT", "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -1841,13 +2020,57 @@ "version": "0.7.0", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", - "dev": true + "dev": true, + "license": "MIT" + }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "license": "ISC", + "optional": true, + "peer": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } }, "node_modules/cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", "dev": true, + "license": "MIT", "dependencies": { "restore-cursor": "^3.1.0" }, @@ -1860,6 +2083,7 @@ "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-3.0.0.tgz", "integrity": "sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw==", "dev": true, + "license": "ISC", "engines": { "node": ">= 10" } @@ -1868,6 +2092,7 @@ "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "license": "ISC", "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", @@ -1881,6 +2106,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "license": "MIT", "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", @@ -1897,6 +2123,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "license": "MIT", "dependencies": { "color-name": "~1.1.4" }, @@ -1907,13 +2134,15 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "license": "MIT" }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "dev": true, + "license": "MIT", "dependencies": { "delayed-stream": "~1.0.0" }, @@ -1926,6 +2155,7 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz", "integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==", "dev": true, + "license": "MIT", "engines": { "node": ">= 6" } @@ -1934,13 +2164,15 @@ "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/convert-source-map": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/core-js": { "version": "2.6.12", @@ -1948,19 +2180,22 @@ "integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==", "deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.", "dev": true, - "hasInstallScript": true + "hasInstallScript": true, + "license": "MIT" }, "node_modules/create-require": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, + "license": "MIT", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -1975,6 +2210,7 @@ "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", "dev": true, + "license": "ISC", "dependencies": { "es5-ext": "^0.10.64", "type": "^2.7.2" @@ -1988,6 +2224,7 @@ "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", "dev": true, + "license": "MIT", "engines": { "node": ">= 12" } @@ -1997,6 +2234,7 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "dev": true, + "license": "MIT", "dependencies": { "ms": "^2.1.3" }, @@ -2014,6 +2252,7 @@ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -2023,6 +2262,7 @@ "resolved": "https://registry.npmjs.org/decamelize-keys/-/decamelize-keys-1.1.1.tgz", "integrity": "sha512-WiPxgEirIV0/eIOMcnFBA3/IJZAZqKnwAwWyvvdi4lsr1WCN22nhdf/3db3DoZcUjTV2SqfzIwNyp6y2xs3nmg==", "dev": true, + "license": "MIT", "dependencies": { "decamelize": "^1.1.0", "map-obj": "^1.0.0" @@ -2039,6 +2279,7 @@ "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-1.0.1.tgz", "integrity": "sha512-7N/q3lyZ+LVCp7PzuxrJr4KMbBE2hW7BT7YNia330OFxIf4d3r5zVpicP2650l7CPN6RM9zOJRl3NGpqSiw3Eg==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -2048,6 +2289,7 @@ "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.2.tgz", "integrity": "sha512-5tdhKF6DbU7iIzrIOa1AOUt39ZRm13cmL1cGEh//aqR8x9+tNfbywRf0n5FD/18OKMdo7DNEtrX2t22ZAkI+eg==", "dev": true, + "license": "MIT", "dependencies": { "is-arguments": "^1.1.1", "is-date-object": "^1.0.5", @@ -2066,13 +2308,15 @@ "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", - "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==" + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "license": "MIT" }, "node_modules/define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", "dev": true, + "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -2090,6 +2334,7 @@ "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", "dev": true, + "license": "MIT", "dependencies": { "define-data-property": "^1.0.1", "has-property-descriptors": "^1.0.0", @@ -2107,6 +2352,7 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.4.0" } @@ -2115,13 +2361,15 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/diff": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/diff/-/diff-7.0.0.tgz", "integrity": "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw==", "dev": true, + "license": "BSD-3-Clause", "engines": { "node": ">=0.3.1" } @@ -2131,6 +2379,7 @@ "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", "dev": true, + "license": "MIT", "dependencies": { "path-type": "^4.0.0" }, @@ -2143,6 +2392,7 @@ "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", "dev": true, + "license": "Apache-2.0", "dependencies": { "esutils": "^2.0.2" }, @@ -2155,6 +2405,7 @@ "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", "dev": true, + "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", @@ -2169,6 +2420,7 @@ "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.3.tgz", "integrity": "sha512-M3BmBhwJRZsSx38lZyhE53Csddgzl5R7xGJNk7CVddZD6CcmwMCH8J+7AprIrQKH7TonKxaCjcv27Qmf+sQ+oA==", "dev": true, + "license": "MIT", "dependencies": { "end-of-stream": "^1.4.1", "inherits": "^2.0.3", @@ -2180,13 +2432,15 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", "dev": true, + "license": "Apache-2.0", "dependencies": { "safe-buffer": "^5.0.1" } @@ -2195,18 +2449,21 @@ "version": "1.5.137", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.137.tgz", "integrity": "sha512-/QSJaU2JyIuTbbABAo/crOs+SuAZLS+fVVS10PVrIT9hrRkmZl8Hb0xPSkKRUUWHQtYzXHpQUW3Dy5hwMzGZkA==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "license": "MIT" }, "node_modules/empower-assert": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/empower-assert/-/empower-assert-1.1.0.tgz", "integrity": "sha512-Ylck0Q6p8y/LpNzYeBccaxAPm2ZyuqBgErgZpO9KT0HuQWF0sJckBKCLmgS1/DEXEiyBi9XtYh3clZm5cAdARw==", "dev": true, + "license": "MIT", "dependencies": { "estraverse": "^4.2.0" } @@ -2216,6 +2473,7 @@ "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", "dev": true, + "license": "MIT", "dependencies": { "once": "^1.4.0" } @@ -2224,6 +2482,7 @@ "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "license": "BSD-2-Clause", "engines": { "node": ">=0.12" }, @@ -2236,6 +2495,7 @@ "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", "dev": true, + "license": "MIT", "dependencies": { "is-arrayish": "^0.2.1" } @@ -2245,6 +2505,7 @@ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" } @@ -2254,6 +2515,7 @@ "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" } @@ -2263,6 +2525,7 @@ "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", "dev": true, + "license": "MIT", "dependencies": { "es-errors": "^1.3.0" }, @@ -2275,6 +2538,7 @@ "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", "dev": true, + "license": "MIT", "dependencies": { "es-errors": "^1.3.0", "get-intrinsic": "^1.2.6", @@ -2291,6 +2555,7 @@ "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", "dev": true, "hasInstallScript": true, + "license": "ISC", "dependencies": { "es6-iterator": "^2.0.3", "es6-symbol": "^3.1.3", @@ -2306,6 +2571,7 @@ "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", "dev": true, + "license": "MIT", "dependencies": { "d": "1", "es5-ext": "^0.10.35", @@ -2317,6 +2583,7 @@ "resolved": "https://registry.npmjs.org/es6-map/-/es6-map-0.1.5.tgz", "integrity": "sha512-mz3UqCh0uPCIqsw1SSAkB/p0rOzF/M0V++vyN7JqlPtSW/VsYgQBvVvqMLmfBuyMzTpLnNqi6JmcSizs4jy19A==", "dev": true, + "license": "MIT", "dependencies": { "d": "1", "es5-ext": "~0.10.14", @@ -2331,6 +2598,7 @@ "resolved": "https://registry.npmjs.org/es6-set/-/es6-set-0.1.6.tgz", "integrity": "sha512-TE3LgGLDIBX332jq3ypv6bcOpkLO0AslAQo7p2VqX/1N46YNsvIWgvjojjSEnWEGWMhr1qUbYeTSir5J6mFHOw==", "dev": true, + "license": "ISC", "dependencies": { "d": "^1.0.1", "es5-ext": "^0.10.62", @@ -2348,6 +2616,7 @@ "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", "dev": true, + "license": "ISC", "dependencies": { "d": "^1.0.2", "ext": "^1.7.0" @@ -2361,6 +2630,7 @@ "resolved": "https://registry.npmjs.org/es6-weak-map/-/es6-weak-map-2.0.3.tgz", "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", "dev": true, + "license": "ISC", "dependencies": { "d": "1", "es5-ext": "^0.10.46", @@ -2372,6 +2642,7 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", + "license": "MIT", "engines": { "node": ">=6" } @@ -2381,6 +2652,7 @@ "resolved": "https://registry.npmjs.org/escallmatch/-/escallmatch-1.5.0.tgz", "integrity": "sha512-iMF4I4I2E16DPusKDgTtQeIBNX0oOS53Ih6sr/2fh+1SDRsXvG8Y3ZOXGWlDkNNo066XBIkfaDRLfZpqcD+vGA==", "dev": true, + "license": "MIT", "dependencies": { "call-matcher": "^1.0.0", "esprima": "^2.0.0" @@ -2391,6 +2663,7 @@ "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz", "integrity": "sha512-OarPfz0lFCiW4/AV2Oy1Rp9qu0iusTKqykwTspGCZtPxmF81JR4MmIebvF1F9+UOKth2ZubLQ4XGGaU+hSn99A==", "dev": true, + "license": "BSD-2-Clause", "bin": { "esparse": "bin/esparse.js", "esvalidate": "bin/esvalidate.js" @@ -2404,6 +2677,7 @@ "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -2415,6 +2689,7 @@ "version": "1.14.3", "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.14.3.tgz", "integrity": "sha512-qFcX0XJkdg+PB3xjZZG/wKSuT1PnQWx57+TVSjIMmILd2yC/6ByYElPwJnslDsuWuSAp4AwJGumarAAmJch5Kw==", + "license": "BSD-2-Clause", "dependencies": { "esprima": "^4.0.1", "estraverse": "^4.2.0", @@ -2437,6 +2712,7 @@ "resolved": "https://registry.npmjs.org/escope/-/escope-3.6.0.tgz", "integrity": "sha512-75IUQsusDdalQEW/G/2esa87J7raqdJF+Ca0/Xm5C3Q58Nr4yVYjZGp/P1+2xiEVgXRrA39dpRb8LcshajbqDQ==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "es6-map": "^0.1.3", "es6-weak-map": "^2.0.1", @@ -2453,6 +2729,7 @@ "integrity": "sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==", "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -2508,6 +2785,7 @@ "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", "dev": true, + "license": "MIT", "bin": { "eslint-config-prettier": "bin/cli.js" }, @@ -2520,6 +2798,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-es/-/eslint-plugin-es-4.1.0.tgz", "integrity": "sha512-GILhQTnjYE2WorX5Jyi5i4dz5ALWxBIdQECVQavL6s7cI76IZTDWleTHkxz/QT3kvcs2QlGHvKLYsSlPOlPXnQ==", "dev": true, + "license": "MIT", "dependencies": { "eslint-utils": "^2.0.0", "regexpp": "^3.0.0" @@ -2539,6 +2818,7 @@ "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", "dev": true, + "license": "MIT", "dependencies": { "eslint-visitor-keys": "^1.1.0" }, @@ -2554,6 +2834,7 @@ "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=4" } @@ -2563,6 +2844,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-15.7.0.tgz", "integrity": "sha512-jDex9s7D/Qial8AGVIHq4W7NswpUD5DPDL2RH8Lzd9EloWUuvUkHfv4FRLMipH5q2UtyurorBkPeNi1wVWNh3Q==", "dev": true, + "license": "MIT", "dependencies": { "builtins": "^5.0.1", "eslint-plugin-es": "^4.1.0", @@ -2612,6 +2894,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -2624,6 +2907,7 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", "dev": true, + "license": "MIT", "dependencies": { "prettier-linter-helpers": "^1.0.0", "synckit": "^0.9.1" @@ -2654,6 +2938,7 @@ "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^4.1.1" @@ -2667,6 +2952,7 @@ "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", "dev": true, + "license": "MIT", "dependencies": { "eslint-visitor-keys": "^2.0.0" }, @@ -2685,6 +2971,7 @@ "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=10" } @@ -2693,6 +2980,7 @@ "version": "3.4.3", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "license": "Apache-2.0", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -2716,6 +3004,7 @@ "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" @@ -2732,6 +3021,7 @@ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true, + "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } @@ -2741,6 +3031,7 @@ "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, + "license": "MIT", "dependencies": { "type-fest": "^0.20.2" }, @@ -2769,6 +3060,7 @@ "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", "dev": true, + "license": "MIT", "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", @@ -2786,6 +3078,7 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true, + "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=10" }, @@ -2798,6 +3091,7 @@ "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", "dev": true, + "license": "ISC", "dependencies": { "d": "^1.0.1", "es5-ext": "^0.10.62", @@ -2813,6 +3107,7 @@ "resolved": "https://registry.npmjs.org/espower/-/espower-2.1.2.tgz", "integrity": "sha512-2qa3aEFtcgPB782jTKDPu82hOdw8+zJsWdOn12Tey8XlexHTqsYUIdLC2B7cUECENXly0vZblH1CEZcqttPNjw==", "dev": true, + "license": "MIT", "dependencies": { "array-find": "^1.0.0", "escallmatch": "^1.5.0", @@ -2830,6 +3125,7 @@ "resolved": "https://registry.npmjs.org/espower-location-detector/-/espower-location-detector-1.0.0.tgz", "integrity": "sha512-Y/3H6ytYwqC3YcOc0gOU22Lp3eI5GAFGOymTdzFyfaiglKgtsw2dePOgXY3yrV+QcLPMPiVYwBU9RKaDoh2bbQ==", "dev": true, + "license": "MIT", "dependencies": { "is-url": "^1.2.1", "path-is-absolute": "^1.0.0", @@ -2842,6 +3138,7 @@ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", "dev": true, + "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" } @@ -2851,6 +3148,7 @@ "resolved": "https://registry.npmjs.org/espower-source/-/espower-source-2.3.0.tgz", "integrity": "sha512-Wc4kC4zUAEV7Qt31JRPoBUc5jjowHRylml2L2VaDQ1XEbnqQofGWx+gPR03TZAPokAMl5dqyL36h3ITyMXy3iA==", "dev": true, + "license": "MIT", "dependencies": { "acorn": "^5.0.0", "acorn-es7-plugin": "^1.0.10", @@ -2874,6 +3172,7 @@ "resolved": "https://registry.npmjs.org/espower-typescript/-/espower-typescript-10.0.1.tgz", "integrity": "sha512-Otz3g+JKQCPG3CxyUQnmcmr9LeYXe+bEU2F/WtBeaByIj+kgR+8lyYSa1Rcqh27b/sp9EjrDLDUTW+d7dsfJQw==", "dev": true, + "license": "MIT", "dependencies": { "espower-source": "^2.3.0", "minimatch": "^5.1.0", @@ -2892,6 +3191,7 @@ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", "dev": true, + "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" } @@ -2900,6 +3200,7 @@ "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", + "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.9.0", "acorn-jsx": "^5.3.2", @@ -2916,6 +3217,7 @@ "version": "8.14.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz", "integrity": "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg==", + "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -2927,6 +3229,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "license": "MIT", "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } @@ -2935,6 +3238,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "license": "BSD-2-Clause", "bin": { "esparse": "bin/esparse.js", "esvalidate": "bin/esvalidate.js" @@ -2948,6 +3252,7 @@ "resolved": "https://registry.npmjs.org/espurify/-/espurify-1.8.1.tgz", "integrity": "sha512-ZDko6eY/o+D/gHCWyHTU85mKDgYcS4FJj7S+YD6WIInm7GQ6AnOjmcL4+buFV/JOztVLELi/7MmuGU5NHta0Mg==", "dev": true, + "license": "MIT", "dependencies": { "core-js": "^2.0.0" } @@ -2957,6 +3262,7 @@ "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz", "integrity": "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "estraverse": "^5.1.0" }, @@ -2969,6 +3275,7 @@ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true, + "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } @@ -2978,6 +3285,7 @@ "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "estraverse": "^5.2.0" }, @@ -2990,6 +3298,7 @@ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true, + "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } @@ -2998,6 +3307,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } @@ -3006,6 +3316,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "license": "BSD-2-Clause", "engines": { "node": ">=0.10.0" } @@ -3015,6 +3326,7 @@ "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", "dev": true, + "license": "MIT", "dependencies": { "d": "1", "es5-ext": "~0.10.14" @@ -3025,6 +3337,7 @@ "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -3034,6 +3347,7 @@ "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", "dev": true, + "license": "MIT", "dependencies": { "cross-spawn": "^7.0.3", "get-stream": "^6.0.0", @@ -3057,6 +3371,7 @@ "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", "dev": true, + "license": "ISC", "dependencies": { "type": "^2.7.2" } @@ -3065,13 +3380,15 @@ "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/external-editor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.1.0.tgz", "integrity": "sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==", "dev": true, + "license": "MIT", "dependencies": { "chardet": "^0.7.0", "iconv-lite": "^0.4.24", @@ -3085,19 +3402,22 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/fast-diff": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", - "dev": true + "dev": true, + "license": "Apache-2.0" }, "node_modules/fast-glob": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -3114,6 +3434,7 @@ "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, + "license": "ISC", "dependencies": { "is-glob": "^4.0.1" }, @@ -3125,12 +3446,14 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==" + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "license": "MIT" }, "node_modules/fast-xml-builder": { "version": "1.1.5", @@ -3175,6 +3498,7 @@ "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.19.1.tgz", "integrity": "sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==", "dev": true, + "license": "ISC", "dependencies": { "reusify": "^1.0.4" } @@ -3194,6 +3518,7 @@ "url": "https://paypal.me/jimmywarting" } ], + "license": "MIT", "dependencies": { "node-domexception": "^1.0.0", "web-streams-polyfill": "^3.0.3" @@ -3207,6 +3532,7 @@ "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", "dev": true, + "license": "MIT", "dependencies": { "escape-string-regexp": "^1.0.5" }, @@ -3222,6 +3548,7 @@ "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.8.0" } @@ -3231,6 +3558,7 @@ "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", "dev": true, + "license": "MIT", "dependencies": { "flat-cache": "^3.0.4" }, @@ -3243,6 +3571,7 @@ "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, + "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -3255,6 +3584,7 @@ "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, + "license": "MIT", "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" @@ -3271,6 +3601,7 @@ "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true, + "license": "BSD-3-Clause", "bin": { "flat": "cli.js" } @@ -3280,6 +3611,7 @@ "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", "dev": true, + "license": "MIT", "dependencies": { "flatted": "^3.2.9", "keyv": "^4.5.3", @@ -3301,6 +3633,7 @@ "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz", "integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==", "dev": true, + "license": "ISC", "dependencies": { "cross-spawn": "^7.0.6", "signal-exit": "^4.0.1" @@ -3317,6 +3650,7 @@ "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", "dev": true, + "license": "ISC", "engines": { "node": ">=14" }, @@ -3329,6 +3663,7 @@ "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.5.tgz", "integrity": "sha512-jqdObeR2rxZZbPSGL+3VckHMYtu+f9//KXBsVny6JSX/pa38Fy+bGjuG8eW/H6USNQWhLi8Num++cU2yOCNz4A==", "dev": true, + "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -3346,6 +3681,7 @@ "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", "dev": true, + "license": "MIT", "dependencies": { "fetch-blob": "^3.1.2" }, @@ -3356,13 +3692,31 @@ "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "license": "ISC" + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", "dev": true, + "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -3372,6 +3726,7 @@ "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", "dev": true, + "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -3618,6 +3973,7 @@ "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-6.7.1.tgz", "integrity": "sha512-LDODD4TMYx7XXdpwxAVRAIAuB0bzv0s+ywFonY46k126qzQHT9ygyoa9tncmOiQmmDrik65UYsEkv3lbfqQ3yQ==", "dev": true, + "license": "Apache-2.0", "dependencies": { "extend": "^3.0.2", "https-proxy-agent": "^7.0.1", @@ -3633,11 +3989,13 @@ "version": "9.0.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "deprecated": "uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).", "dev": true, "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" ], + "license": "MIT", "bin": { "uuid": "dist/bin/uuid" } @@ -3647,6 +4005,7 @@ "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-6.1.1.tgz", "integrity": "sha512-a4tiq7E0/5fTjxPAaH4jpjkSv/uCaU2p5KC6HVGrvl0cDjA8iBZv4vv1gyzlmK0ZUKqwpOyQMKzZQe3lTit77A==", "dev": true, + "license": "Apache-2.0", "dependencies": { "gaxios": "^6.1.1", "google-logging-utils": "^0.0.2", @@ -3661,6 +4020,7 @@ "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.9.0" } @@ -3669,6 +4029,7 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "license": "ISC", "engines": { "node": "6.* || 8.* || >= 10.*" } @@ -3678,6 +4039,7 @@ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", "dev": true, + "license": "MIT", "dependencies": { "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", @@ -3702,6 +4064,7 @@ "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", "dev": true, + "license": "MIT", "dependencies": { "dunder-proto": "^1.0.1", "es-object-atoms": "^1.0.0" @@ -3715,6 +4078,7 @@ "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -3749,6 +4113,7 @@ "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dev": true, + "license": "ISC", "dependencies": { "is-glob": "^4.0.3" }, @@ -3777,6 +4142,7 @@ "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", "dev": true, + "license": "MIT", "engines": { "node": ">=4" } @@ -3786,6 +4152,7 @@ "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", "dev": true, + "license": "MIT", "dependencies": { "array-union": "^2.1.0", "dir-glob": "^3.0.1", @@ -3806,6 +4173,7 @@ "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.15.1.tgz", "integrity": "sha512-Jb6Z0+nvECVz+2lzSMt9u98UsoakXxA2HGHMCxh+so3n90XgYWkq5dur19JAJV7ONiJY22yBTyJB1TSkvPq9Ng==", "dev": true, + "license": "Apache-2.0", "dependencies": { "base64-js": "^1.3.0", "ecdsa-sig-formatter": "^1.0.11", @@ -3823,6 +4191,7 @@ "resolved": "https://registry.npmjs.org/google-gax/-/google-gax-5.1.1-rc.1.tgz", "integrity": "sha512-HSHw7NytSxiyTp3WgWQXu4Cnl49VH2qRcAU047fmShUbbxkGwYX3MlipxhDkWIWMRl7Dktyq2gRvwQVP6ILgUA==", "dev": true, + "license": "Apache-2.0", "dependencies": { "@grpc/grpc-js": "^1.12.6", "@grpc/proto-loader": "^0.7.13", @@ -3846,6 +4215,7 @@ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", "dev": true, + "license": "MIT", "dependencies": { "debug": "4" }, @@ -3858,6 +4228,7 @@ "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-7.0.0-rc.5.tgz", "integrity": "sha512-s9rlpplwdb/KCq2DYevVTM/MpozeVZuR3pkzDGXtRhY7wD4fXftIYXUAerX07ZPB3J8/dHUJsX7fPnN2O4Psuw==", "dev": true, + "license": "Apache-2.0", "dependencies": { "extend": "^3.0.2", "https-proxy-agent": "^7.0.1", @@ -3872,6 +4243,7 @@ "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-7.0.0-rc.1.tgz", "integrity": "sha512-E6c+AdIaK1LNA839OyotiTca+B2IG1nDlMjnlcck8JjXn3fVgx57Ib9i6iL1/iqN7bA3EUQdcRRu+HqOCOABIg==", "dev": true, + "license": "Apache-2.0", "dependencies": { "gaxios": "^7.0.0-rc.1", "google-logging-utils": "^1.0.0", @@ -3886,6 +4258,7 @@ "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-10.0.0-rc.2.tgz", "integrity": "sha512-LjkDUtHV8mFFV0pDWpPTjUuAPd6WDBs2y/mTzGSmwQJkDRinOpQyu7e/0pqQoDoanKGwaQJH5729uZ+/5Uz8fw==", "dev": true, + "license": "Apache-2.0", "dependencies": { "base64-js": "^1.3.0", "ecdsa-sig-formatter": "^1.0.11", @@ -3904,6 +4277,7 @@ "resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-1.1.1.tgz", "integrity": "sha512-rcX58I7nqpu4mbKztFeOAObbomBbHU2oIb/d3tJfF3dizGSApqtSwYJigGCooHdnMyQBIw8BrWyK96w3YXgr6A==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=14" } @@ -3913,6 +4287,7 @@ "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-8.0.0-rc.1.tgz", "integrity": "sha512-UjE/egX6ixArdcCKOkheuFQ4XN4/0gX92nd2JPVEYuRU2sWHAWuOVGnowm1fQUdQtaxqn1n8H0hOb2LCaUhJ3A==", "dev": true, + "license": "MIT", "dependencies": { "gaxios": "^7.0.0-rc.1", "jws": "^4.0.0" @@ -3926,6 +4301,7 @@ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "dev": true, + "license": "MIT", "dependencies": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", @@ -3940,12 +4316,12 @@ } }, "node_modules/google-gax/node_modules/retry-request": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/retry-request/-/retry-request-8.0.0.tgz", - "integrity": "sha512-dJkZNmyV9C8WKUmbdj1xcvVlXBSvsUQCkg89TCK8rD72RdSn9A2jlXlS2VuYSTHoPJjJEfUHhjNYrlvuksF9cg==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/retry-request/-/retry-request-8.0.2.tgz", + "integrity": "sha512-JzFPAfklk1kjR1w76f0QOIhoDkNkSqW8wYKT08n9yysTmZfB+RQ2QoXoTAeOi1HD9ZipTyTAZg3c4pM/jeqgSw==", "dev": true, + "license": "MIT", "dependencies": { - "@types/request": "^2.48.12", "extend": "^3.0.2", "teeny-request": "^10.0.0" }, @@ -3958,6 +4334,7 @@ "resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-10.1.0.tgz", "integrity": "sha512-3ZnLvgWF29jikg1sAQ1g0o+lr5JX6sVgYvfUJazn7ZjJroDBUTWp44/+cFVX0bULjv4vci+rBD+oGVAkWqhUbw==", "dev": true, + "license": "Apache-2.0", "dependencies": { "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0", @@ -3973,6 +4350,7 @@ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", "dev": true, + "license": "MIT", "dependencies": { "agent-base": "6", "debug": "4" @@ -3986,6 +4364,7 @@ "resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-0.0.2.tgz", "integrity": "sha512-NEgUnEcBiP5HrPzufUkBzJOD/Sxsco3rLNo1F1TNf7ieU8ryUzBhqba8r756CjLX7rn3fHl6iLEwPYuqpoKgQQ==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=14" } @@ -4034,6 +4413,7 @@ "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -4044,19 +4424,22 @@ "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "license": "ISC" }, "node_modules/graphemer": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/gtoken": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-7.1.0.tgz", "integrity": "sha512-pCcEwRi+TKpMlxAQObHDQ56KawURgyAf6jtIY046fJ5tIv3zDe/LEIubckAO8fj6JnAxLdmWkUfNyulQ2iKdEw==", "dev": true, + "license": "MIT", "dependencies": { "gaxios": "^6.0.0", "jws": "^4.0.0" @@ -4070,6 +4453,7 @@ "resolved": "https://registry.npmjs.org/gts/-/gts-6.0.2.tgz", "integrity": "sha512-lp9+eDzzm6TYqiBpgGY00EInxBHFTJiU5brsVp11qXCJEw7Q6WNNngja0spZeqSFWSquaRuHQUuWxdZLaxnKmw==", "dev": true, + "license": "Apache-2.0", "dependencies": { "@typescript-eslint/eslint-plugin": "5.62.0", "@typescript-eslint/parser": "5.62.0", @@ -4102,6 +4486,7 @@ "resolved": "https://registry.npmjs.org/hard-rejection/-/hard-rejection-2.1.0.tgz", "integrity": "sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -4110,6 +4495,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "license": "MIT", "engines": { "node": ">=8" } @@ -4119,6 +4505,7 @@ "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", "dev": true, + "license": "MIT", "dependencies": { "es-define-property": "^1.0.0" }, @@ -4131,6 +4518,7 @@ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -4143,6 +4531,7 @@ "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", "dev": true, + "license": "MIT", "dependencies": { "has-symbols": "^1.0.3" }, @@ -4158,6 +4547,7 @@ "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", "dev": true, + "license": "MIT", "dependencies": { "function-bind": "^1.1.2" }, @@ -4170,6 +4560,7 @@ "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true, + "license": "MIT", "bin": { "he": "bin/he" } @@ -4179,6 +4570,7 @@ "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-4.1.0.tgz", "integrity": "sha512-kyCuEOWjJqZuDbRHzL8V93NzQhwIB71oFWSyzVo+KPZI+pnQPPxucdkrOZvkLRnrf5URsQM+IJ09Dw29cRALIA==", "dev": true, + "license": "ISC", "dependencies": { "lru-cache": "^6.0.0" }, @@ -4191,6 +4583,7 @@ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", "dev": true, + "license": "ISC", "dependencies": { "yallist": "^4.0.0" }, @@ -4202,7 +4595,8 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/html-entities": { "version": "2.6.0", @@ -4218,13 +4612,15 @@ "type": "patreon", "url": "https://patreon.com/mdevils" } - ] + ], + "license": "MIT" }, "node_modules/http-proxy-agent": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", "dev": true, + "license": "MIT", "dependencies": { "@tootallnate/once": "2", "agent-base": "6", @@ -4239,6 +4635,7 @@ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", "dev": true, + "license": "MIT", "dependencies": { "debug": "4" }, @@ -4251,6 +4648,7 @@ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", "dev": true, + "license": "MIT", "dependencies": { "agent-base": "^7.1.2", "debug": "4" @@ -4264,6 +4662,7 @@ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=10.17.0" } @@ -4273,6 +4672,7 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "dev": true, + "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3" }, @@ -4285,6 +4685,7 @@ "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 4" } @@ -4294,6 +4695,7 @@ "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", "dev": true, + "license": "MIT", "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -4310,6 +4712,7 @@ "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.8.19" } @@ -4319,6 +4722,7 @@ "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -4328,6 +4732,7 @@ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", + "license": "ISC", "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -4336,13 +4741,15 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" }, "node_modules/inquirer": { "version": "7.3.3", "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-7.3.3.tgz", "integrity": "sha512-JG3eIAj5V9CwcGvuOmoo6LB9kbAYT8HXffUl6memuszlwDC/qvFAJw49XJ5NROSFNPxp3iQg1GqkFhaY/CR0IA==", "dev": true, + "license": "MIT", "dependencies": { "ansi-escapes": "^4.2.1", "chalk": "^4.1.0", @@ -4367,6 +4774,7 @@ "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.2.0.tgz", "integrity": "sha512-7bVbi0huj/wrIAOzb8U1aszg9kdi3KN/CyU19CTI7tAoZYEZoL9yCDXpbXN+uPsuWnP02cyug1gleqq+TU+YCA==", "dev": true, + "license": "MIT", "dependencies": { "call-bound": "^1.0.2", "has-tostringtag": "^1.0.2" @@ -4382,13 +4790,30 @@ "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", - "dev": true + "dev": true, + "license": "MIT" + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } }, "node_modules/is-core-module": { "version": "2.16.1", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", "integrity": "sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==", "dev": true, + "license": "MIT", "dependencies": { "hasown": "^2.0.2" }, @@ -4404,6 +4829,7 @@ "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.1.0.tgz", "integrity": "sha512-PwwhEakHVKTdRNVOw+/Gyh0+MzlCl4R6qKvkhuvLtPMggI1WAHt9sOwZxQLSGpUaDnrdyDsomoRgNnCfKNSXXg==", "dev": true, + "license": "MIT", "dependencies": { "call-bound": "^1.0.2", "has-tostringtag": "^1.0.2" @@ -4420,6 +4846,7 @@ "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -4428,6 +4855,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "license": "MIT", "engines": { "node": ">=8" } @@ -4437,6 +4865,7 @@ "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, + "license": "MIT", "dependencies": { "is-extglob": "^2.1.1" }, @@ -4449,6 +4878,7 @@ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -4458,6 +4888,7 @@ "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -4467,6 +4898,7 @@ "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", "integrity": "sha512-yvkRyxmFKEOQ4pNXCmJG5AEQNlXJS5LaONXo5/cLdTZdWvsZ1ioJEonLGAosKlMWE8lwUy/bJzMjcw8az73+Fg==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -4476,6 +4908,7 @@ "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz", "integrity": "sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==", "dev": true, + "license": "MIT", "dependencies": { "call-bound": "^1.0.2", "gopd": "^1.2.0", @@ -4494,6 +4927,7 @@ "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" }, @@ -4506,6 +4940,7 @@ "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -4517,19 +4952,22 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/is-url/-/is-url-1.2.4.tgz", "integrity": "sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/jackspeak": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", "integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==", "dev": true, + "license": "BlueOak-1.0.0", "dependencies": { "@isaacs/cliui": "^8.0.2" }, @@ -4544,7 +4982,8 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/js-yaml": { "version": "4.1.1", @@ -4562,6 +5001,7 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-4.0.2.tgz", "integrity": "sha512-6n4D8gLlLf1n5mNLQPRfViYzu9RATblzPEtm1SthMX1Pjao0r9YI9nw7ZIfRxQMERS87mcswrg+r/OYrPRX6jA==", + "license": "Apache-2.0", "dependencies": { "xmlcreate": "^2.0.4" } @@ -4570,6 +5010,7 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.4.tgz", "integrity": "sha512-zeFezwyXeG4syyYHbvh1A967IAqq/67yXtXvuL5wnqCkFZe8I0vKfm+EO+YEvLguo6w9CDUbrAXVtJSHh2E8rw==", + "license": "Apache-2.0", "dependencies": { "@babel/parser": "^7.20.15", "@jsdoc/salty": "^0.2.1", @@ -4598,6 +5039,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", + "license": "MIT", "engines": { "node": ">=8" } @@ -4607,6 +5049,7 @@ "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", "dev": true, + "license": "MIT", "bin": { "jsesc": "bin/jsesc" }, @@ -4619,6 +5062,7 @@ "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", "dev": true, + "license": "MIT", "dependencies": { "bignumber.js": "^9.0.0" } @@ -4627,31 +5071,36 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/json-parse-even-better-errors": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/json5": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true, + "license": "MIT", "bin": { "json5": "lib/cli.js" }, @@ -4687,6 +5136,7 @@ "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", "dev": true, + "license": "MIT", "dependencies": { "json-buffer": "3.0.1" } @@ -4696,6 +5146,7 @@ "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -4704,6 +5155,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/klaw/-/klaw-3.0.0.tgz", "integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==", + "license": "MIT", "dependencies": { "graceful-fs": "^4.1.9" } @@ -4713,6 +5165,7 @@ "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, + "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" @@ -4725,12 +5178,14 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/linkify-it": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", "integrity": "sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==", + "license": "MIT", "dependencies": { "uc.micro": "^2.0.0" } @@ -4740,6 +5195,7 @@ "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, + "license": "MIT", "dependencies": { "p-locate": "^5.0.0" }, @@ -4760,19 +5216,22 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", "dev": true, + "license": "MIT", "dependencies": { "chalk": "^4.1.0", "is-unicode-supported": "^0.1.0" @@ -4787,13 +5246,15 @@ "node_modules/long": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", - "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==" + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", "dev": true, + "license": "ISC", "dependencies": { "yallist": "^3.0.2" } @@ -4802,13 +5263,15 @@ "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/map-obj": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.3.0.tgz", "integrity": "sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" }, @@ -4837,6 +5300,7 @@ "version": "8.6.7", "resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-8.6.7.tgz", "integrity": "sha512-FlCHFwNnutLgVTflOYHPW2pPcl2AACqVzExlkGQNsi4CJgqOHN7YTgDd4LuhgN1BFO3TS0vLAruV1Td6dwWPJA==", + "license": "Unlicense", "peerDependencies": { "@types/markdown-it": "*", "markdown-it": "*" @@ -4846,6 +5310,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/marked/-/marked-4.3.0.tgz", "integrity": "sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A==", + "license": "MIT", "bin": { "marked": "bin/marked.js" }, @@ -4858,6 +5323,7 @@ "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" } @@ -4865,13 +5331,15 @@ "node_modules/mdurl": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.0.0.tgz", - "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==" + "integrity": "sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==", + "license": "MIT" }, "node_modules/meow": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/meow/-/meow-9.0.0.tgz", "integrity": "sha512-+obSblOQmRhcyBt62furQqRAQpNyWXo8BuQ5bN7dG8wmwQ+vwHKp/rCFD4CrTP8CsDQD1sjoZ94K417XEUk8IQ==", "dev": true, + "license": "MIT", "dependencies": { "@types/minimist": "^1.2.0", "camelcase-keys": "^6.2.2", @@ -4898,6 +5366,7 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.18.1.tgz", "integrity": "sha512-OIAYXk8+ISY+qTOwkHtKqzAuxchoMiD9Udx+FSGQDuiRR+PJKJHc2NJAXlbhkGwTt/4/nKZxELY1w3ReWOL8mw==", "dev": true, + "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=10" }, @@ -4910,6 +5379,7 @@ "resolved": "https://registry.npmjs.org/merge-estraverse-visitors/-/merge-estraverse-visitors-1.0.0.tgz", "integrity": "sha512-YcT59TImpdL2qe+I7OWI+ESjBVov9CWTQjK9Issk58BNQzyputg2s8wOE+DDvxtgmPHG4L6xAl0yAwbNCyXszg==", "dev": true, + "license": "MIT", "dependencies": { "estraverse": "^4.0.0" } @@ -4918,13 +5388,15 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", "dev": true, + "license": "MIT", "engines": { "node": ">= 8" } @@ -4934,6 +5406,7 @@ "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, + "license": "MIT", "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" @@ -4947,6 +5420,7 @@ "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", "dev": true, + "license": "MIT", "bin": { "mime": "cli.js" }, @@ -4959,6 +5433,7 @@ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -4968,6 +5443,7 @@ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "dev": true, + "license": "MIT", "dependencies": { "mime-db": "1.52.0" }, @@ -4980,6 +5456,7 @@ "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -4989,6 +5466,7 @@ "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", "dev": true, + "license": "MIT", "engines": { "node": ">=4" } @@ -5009,6 +5487,7 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -5018,6 +5497,7 @@ "resolved": "https://registry.npmjs.org/minimist-options/-/minimist-options-4.1.0.tgz", "integrity": "sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==", "dev": true, + "license": "MIT", "dependencies": { "arrify": "^1.0.1", "is-plain-obj": "^1.1.0", @@ -5032,6 +5512,7 @@ "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -5041,6 +5522,7 @@ "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", "dev": true, + "license": "ISC", "engines": { "node": ">=16 || 14 >=14.17" } @@ -5049,6 +5531,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "license": "MIT", "bin": { "mkdirp": "bin/cmd.js" }, @@ -5169,13 +5652,15 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/multi-stage-sourcemap": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/multi-stage-sourcemap/-/multi-stage-sourcemap-0.2.1.tgz", "integrity": "sha512-umaOM+8BZByZIB/ciD3dQLzTv50rEkkGJV78ta/tIVc/J/rfGZY5y1R+fBD3oTaolx41mK8rRcyGtYbDXlzx8Q==", "dev": true, + "license": "MIT", "dependencies": { "source-map": "^0.1.34" } @@ -5196,25 +5681,29 @@ "version": "0.0.8", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/natural-compare-lite": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz", "integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/ncp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", "integrity": "sha512-zIdGUrPRFTUELUvr3Gmc7KZ2Sw/h1PiVM0Af/oHB6zgnV1ikqSfRk+TOufi79aHYCW3NiOXmr1BP5nWbzojLaA==", "dev": true, + "license": "MIT", "bin": { "ncp": "bin/ncp" } @@ -5223,7 +5712,8 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/node-domexception": { "version": "1.0.0", @@ -5241,6 +5731,7 @@ "url": "https://paypal.me/jimmywarting" } ], + "license": "MIT", "engines": { "node": ">=10.5.0" } @@ -5250,6 +5741,7 @@ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dev": true, + "license": "MIT", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -5269,13 +5761,15 @@ "version": "2.0.19", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.19.tgz", "integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/normalize-package-data": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-3.0.3.tgz", "integrity": "sha512-p2W1sgqij3zMMyRC067Dg16bfzVH+w7hyegmpIvZ4JNjqtGOVAIvLmjBx3yP7YTe9vKJgkoNOPjwQGogDoMXFA==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "hosted-git-info": "^4.0.1", "is-core-module": "^2.5.0", @@ -5291,6 +5785,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -5298,11 +5793,24 @@ "node": ">=10" } }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/npm-run-path": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", "dev": true, + "license": "MIT", "dependencies": { "path-key": "^3.0.0" }, @@ -5315,6 +5823,7 @@ "resolved": "https://registry.npmjs.org/nunjucks/-/nunjucks-3.2.4.tgz", "integrity": "sha512-26XRV6BhkgK0VOxfbU5cQI+ICFUtMLixv1noZn1tGU38kQH5A5nmmbk/O45xdyBhD1esk47nKrY0mvQpZIhRjQ==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "a-sync-waterfall": "^1.0.0", "asap": "^2.0.3", @@ -5339,6 +5848,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz", "integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==", + "license": "MIT", "engines": { "node": ">= 6" } @@ -5348,6 +5858,7 @@ "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", "dev": true, + "license": "MIT", "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1" @@ -5364,6 +5875,7 @@ "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" } @@ -5372,6 +5884,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", "dependencies": { "wrappy": "1" } @@ -5381,6 +5894,7 @@ "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", "dev": true, + "license": "MIT", "dependencies": { "mimic-fn": "^2.1.0" }, @@ -5395,6 +5909,7 @@ "version": "0.8.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", "integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==", + "license": "MIT", "dependencies": { "deep-is": "~0.1.3", "fast-levenshtein": "~2.0.6", @@ -5411,6 +5926,7 @@ "version": "0.3.0", "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", "integrity": "sha512-0OO4y2iOHix2W6ujICbKIaEQXvFQHue65vUG3pb5EUomzPI90z9hsA1VsO/dbIIpC53J8gxM9Q4Oho0jrCM/yA==", + "license": "MIT", "dependencies": { "prelude-ls": "~1.1.2", "type-check": "~0.3.2" @@ -5431,6 +5947,7 @@ "version": "0.3.2", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", "integrity": "sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg==", + "license": "MIT", "dependencies": { "prelude-ls": "~1.1.2" }, @@ -5443,6 +5960,7 @@ "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", "integrity": "sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -5452,6 +5970,7 @@ "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, + "license": "MIT", "dependencies": { "yocto-queue": "^0.1.0" }, @@ -5467,6 +5986,7 @@ "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, + "license": "MIT", "dependencies": { "p-limit": "^3.0.2" }, @@ -5482,6 +6002,7 @@ "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -5490,13 +6011,15 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", - "dev": true + "dev": true, + "license": "BlueOak-1.0.0" }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", "dev": true, + "license": "MIT", "dependencies": { "callsites": "^3.0.0" }, @@ -5509,6 +6032,7 @@ "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", "dev": true, + "license": "MIT", "dependencies": { "@babel/code-frame": "^7.0.0", "error-ex": "^1.3.1", @@ -5527,6 +6051,7 @@ "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -5552,6 +6077,7 @@ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -5561,6 +6087,7 @@ "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -5569,13 +6096,15 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/path-scurry": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", "dev": true, + "license": "BlueOak-1.0.0", "dependencies": { "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" @@ -5591,13 +6120,15 @@ "version": "10.4.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -5606,7 +6137,8 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/picomatch": { "version": "2.3.2", @@ -5626,6 +6158,7 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.8.0" } @@ -5635,6 +6168,7 @@ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", "dev": true, + "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, @@ -5650,6 +6184,7 @@ "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", "dev": true, + "license": "MIT", "dependencies": { "fast-diff": "^1.1.2" }, @@ -5697,6 +6232,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/protobufjs-cli/-/protobufjs-cli-1.2.0.tgz", "integrity": "sha512-+YvqJEmsmZHGzE5j0tvEzFeHm0sX7pzRFpyj7+GazhkS4Y0r+jgbioVvFxxSWIlPzUel/lxeOnLChBmV8NmyHA==", + "license": "BSD-3-Clause", "dependencies": { "chalk": "^4.0.0", "escodegen": "^1.13.0", @@ -5724,6 +6260,7 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } @@ -5732,7 +6269,8 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", - "deprecated": "Glob versions prior to v9 are no longer supported", + "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me", + "license": "ISC", "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -5751,6 +6289,7 @@ "version": "7.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", + "license": "ISC", "bin": { "semver": "bin/semver.js" }, @@ -5762,6 +6301,7 @@ "version": "0.2.3", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==", + "license": "MIT", "engines": { "node": ">=14.14" } @@ -5771,6 +6311,7 @@ "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -5779,6 +6320,7 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", + "license": "MIT", "engines": { "node": ">=6" } @@ -5801,13 +6343,15 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "MIT" }, "node_modules/quick-lru": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", "integrity": "sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -5817,6 +6361,7 @@ "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", "dev": true, + "license": "MIT", "dependencies": { "safe-buffer": "^5.1.0" } @@ -5826,6 +6371,7 @@ "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", "dev": true, + "license": "MIT", "dependencies": { "@types/normalize-package-data": "^2.4.0", "normalize-package-data": "^2.5.0", @@ -5841,6 +6387,7 @@ "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", "dev": true, + "license": "MIT", "dependencies": { "find-up": "^4.1.0", "read-pkg": "^5.2.0", @@ -5858,6 +6405,7 @@ "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", "dev": true, + "license": "MIT", "dependencies": { "locate-path": "^5.0.0", "path-exists": "^4.0.0" @@ -5871,6 +6419,7 @@ "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", "dev": true, + "license": "MIT", "dependencies": { "p-locate": "^4.1.0" }, @@ -5883,6 +6432,7 @@ "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", "dev": true, + "license": "MIT", "dependencies": { "p-try": "^2.0.0" }, @@ -5898,6 +6448,7 @@ "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", "dev": true, + "license": "MIT", "dependencies": { "p-limit": "^2.2.0" }, @@ -5910,6 +6461,7 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", "dev": true, + "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=8" } @@ -5918,13 +6470,15 @@ "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/read-pkg/node_modules/normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "hosted-git-info": "^2.1.4", "resolve": "^1.10.0", @@ -5937,6 +6491,7 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver" } @@ -5946,6 +6501,7 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", "dev": true, + "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=8" } @@ -5955,6 +6511,7 @@ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", "dev": true, + "license": "MIT", "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -5964,11 +6521,27 @@ "node": ">= 6" } }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", "integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==", "dev": true, + "license": "MIT", "dependencies": { "indent-string": "^4.0.0", "strip-indent": "^3.0.0" @@ -5982,6 +6555,7 @@ "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz", "integrity": "sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==", "dev": true, + "license": "MIT", "dependencies": { "call-bind": "^1.0.8", "define-properties": "^1.2.1", @@ -6002,6 +6576,7 @@ "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" }, @@ -6013,6 +6588,7 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -6021,6 +6597,7 @@ "version": "0.2.4", "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.4.tgz", "integrity": "sha512-JRrFk1D4OQ4SqovXOgdav+K8EAhSB/LJZqCz8tbX0KObcdeM15Ss59ozWMBWmmINMagCwmqn4ZNryUGpBsl6Jw==", + "license": "MIT", "dependencies": { "lodash": "^4.17.21" } @@ -6030,6 +6607,7 @@ "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz", "integrity": "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w==", "dev": true, + "license": "MIT", "dependencies": { "is-core-module": "^2.16.0", "path-parse": "^1.0.7", @@ -6050,6 +6628,7 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true, + "license": "MIT", "engines": { "node": ">=4" } @@ -6059,6 +6638,7 @@ "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", "dev": true, + "license": "MIT", "dependencies": { "onetime": "^5.1.0", "signal-exit": "^3.0.2" @@ -6072,6 +6652,7 @@ "resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz", "integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==", "dev": true, + "license": "MIT", "engines": { "node": ">= 4" } @@ -6081,6 +6662,7 @@ "resolved": "https://registry.npmjs.org/retry-request/-/retry-request-7.0.2.tgz", "integrity": "sha512-dUOvLMJ0/JJYEn8NrpOaGNE7X3vpI5XlZS/u0ANjqtcZVKnIxP7IgCFwrKTxENw29emmwug53awKtaMm4i9g5w==", "dev": true, + "license": "MIT", "dependencies": { "@types/request": "^2.48.8", "extend": "^3.0.2", @@ -6095,6 +6677,7 @@ "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", "dev": true, + "license": "MIT", "engines": { "iojs": ">=1.0.0", "node": ">=0.10.0" @@ -6106,6 +6689,7 @@ "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "deprecated": "Rimraf versions prior to v4 are no longer supported", "dev": true, + "license": "ISC", "dependencies": { "glob": "^7.1.3" }, @@ -6131,8 +6715,9 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Glob versions prior to v9 are no longer supported", + "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me", "dev": true, + "license": "ISC", "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -6166,6 +6751,7 @@ "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", "integrity": "sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -6189,6 +6775,7 @@ "url": "https://feross.org/support" } ], + "license": "MIT", "dependencies": { "queue-microtask": "^1.2.2" } @@ -6198,6 +6785,7 @@ "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", "dev": true, + "license": "Apache-2.0", "dependencies": { "tslib": "^1.9.0" }, @@ -6223,19 +6811,22 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "MIT" }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, + "license": "ISC", "bin": { "semver": "bin/semver.js" } @@ -6245,6 +6836,7 @@ "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "randombytes": "^2.1.0" } @@ -6254,6 +6846,7 @@ "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", "dev": true, + "license": "MIT", "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -6271,6 +6864,7 @@ "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.2.tgz", "integrity": "sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==", "dev": true, + "license": "MIT", "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -6286,6 +6880,7 @@ "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "dev": true, + "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" }, @@ -6298,6 +6893,7 @@ "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -6306,13 +6902,15 @@ "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -6322,6 +6920,7 @@ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "devOptional": true, + "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" } @@ -6331,6 +6930,7 @@ "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", "dev": true, + "license": "MIT", "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -6341,6 +6941,7 @@ "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz", "integrity": "sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==", "dev": true, + "license": "Apache-2.0", "dependencies": { "spdx-expression-parse": "^3.0.0", "spdx-license-ids": "^3.0.0" @@ -6350,13 +6951,15 @@ "version": "2.5.0", "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.5.0.tgz", "integrity": "sha512-PiU42r+xO4UbUS1buo3LPJkjlO7430Xn5SVAhdpzzsPHsjbYVflnnFdATgabnLude+Cqu25p6N+g2lw/PFsa4w==", - "dev": true + "dev": true, + "license": "CC-BY-3.0" }, "node_modules/spdx-expression-parse": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", "dev": true, + "license": "MIT", "dependencies": { "spdx-exceptions": "^2.1.0", "spdx-license-ids": "^3.0.0" @@ -6366,13 +6969,15 @@ "version": "3.0.21", "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.21.tgz", "integrity": "sha512-Bvg/8F5XephndSK3JffaRqdT+gyhfqIPwDHpX80tJrF8QQRYMo8sNMeaZ2Dp5+jhwKnUmIOyFFQfHRkjJm5nXg==", - "dev": true + "dev": true, + "license": "CC0-1.0" }, "node_modules/stream-events": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/stream-events/-/stream-events-1.0.5.tgz", "integrity": "sha512-E1GUzBSgvct8Jsb3v2X15pjzN1tYebtbLaMg+eBOUOAxgbLoSbT2NS91ckc5lJD1KfLjId+jXJRgo0qnV5Nerg==", "dev": true, + "license": "MIT", "dependencies": { "stubs": "^3.0.0" } @@ -6381,13 +6986,15 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.3.tgz", "integrity": "sha512-76ORR0DO1o1hlKwTbi/DM3EXWGf3ZJYO8cXX5RJwnul2DEg2oyoZyjLNoQM8WsvZiFKCRfC1O0J7iCvie3RZmQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", "dev": true, + "license": "MIT", "dependencies": { "safe-buffer": "~5.2.0" } @@ -6396,6 +7003,7 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "license": "MIT", "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -6411,6 +7019,7 @@ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "dev": true, + "license": "MIT", "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -6424,6 +7033,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "license": "MIT", "dependencies": { "ansi-regex": "^5.0.1" }, @@ -6437,6 +7047,7 @@ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, + "license": "MIT", "dependencies": { "ansi-regex": "^5.0.1" }, @@ -6449,6 +7060,7 @@ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -6458,6 +7070,7 @@ "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", "dev": true, + "license": "MIT", "dependencies": { "min-indent": "^1.0.0" }, @@ -6469,6 +7082,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "license": "MIT", "engines": { "node": ">=8" }, @@ -6493,12 +7107,14 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/stubs/-/stubs-3.0.0.tgz", "integrity": "sha512-PdHt7hHUJKxvTCgbKX9C1V/ftOcjJQgz8BZwNfV5c4B6dcGqlpelTbJ999jBGZ2jYiPAwcX5dP6oBwVlBlUbxw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "license": "MIT", "dependencies": { "has-flag": "^4.0.0" }, @@ -6511,6 +7127,7 @@ "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -6523,6 +7140,7 @@ "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.2.tgz", "integrity": "sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==", "dev": true, + "license": "MIT", "dependencies": { "@pkgr/core": "^0.1.0", "tslib": "^2.6.2" @@ -6538,13 +7156,15 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "dev": true + "dev": true, + "license": "0BSD" }, "node_modules/teeny-request": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-9.0.0.tgz", "integrity": "sha512-resvxdc6Mgb7YEThw6G6bExlXKkv6+YbuzGg9xuXxSgxJF7Ozs+o8Y9+2R3sArdWdW8nOokoQb1yrpFB0pQK2g==", "dev": true, + "license": "Apache-2.0", "dependencies": { "http-proxy-agent": "^5.0.0", "https-proxy-agent": "^5.0.0", @@ -6561,6 +7181,7 @@ "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", "dev": true, + "license": "MIT", "dependencies": { "debug": "4" }, @@ -6573,6 +7194,7 @@ "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", "dev": true, + "license": "MIT", "dependencies": { "agent-base": "6", "debug": "4" @@ -6585,11 +7207,13 @@ "version": "9.0.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "deprecated": "uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).", "dev": true, "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" ], + "license": "MIT", "bin": { "uuid": "dist/bin/uuid" } @@ -6598,19 +7222,22 @@ "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", "dev": true, + "license": "MIT", "dependencies": { "os-tmpdir": "~1.0.2" }, @@ -6623,6 +7250,7 @@ "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, + "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, @@ -6634,13 +7262,15 @@ "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/trim-newlines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-newlines/-/trim-newlines-3.0.1.tgz", "integrity": "sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -6650,6 +7280,7 @@ "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, + "license": "MIT", "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -6693,6 +7324,7 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz", "integrity": "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg==", "dev": true, + "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -6705,6 +7337,7 @@ "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true, + "license": "BSD-3-Clause", "engines": { "node": ">=0.3.1" } @@ -6713,13 +7346,15 @@ "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true + "dev": true, + "license": "0BSD" }, "node_modules/tsutils": { "version": "3.21.0", "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", "dev": true, + "license": "MIT", "dependencies": { "tslib": "^1.8.1" }, @@ -6734,13 +7369,15 @@ "version": "2.7.3", "resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz", "integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, + "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1" }, @@ -6753,6 +7390,7 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", "dev": true, + "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=10" }, @@ -6764,13 +7402,15 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/type-name/-/type-name-2.0.2.tgz", "integrity": "sha512-kkgkuqR/jKdKO5oh/I2SMu2dGbLXoJq0zkdgbxaqYK+hr9S9edwVVGf+tMUFTx2gH9TN2+Zu9JZ/Njonb3cjhA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/typescript": { "version": "5.6.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -6782,12 +7422,14 @@ "node_modules/uc.micro": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", - "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==" + "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==", + "license": "MIT" }, "node_modules/uglify-js": { "version": "3.19.3", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.3.tgz", "integrity": "sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==", + "license": "BSD-2-Clause", "bin": { "uglifyjs": "bin/uglifyjs" }, @@ -6804,13 +7446,15 @@ "node_modules/undici-types": { "version": "6.21.0", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", - "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==" + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "license": "MIT" }, "node_modules/universal-user-agent": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.1.tgz", "integrity": "sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/update-browserslist-db": { "version": "1.1.3", @@ -6831,6 +7475,7 @@ "url": "https://github.com/sponsors/ai" } ], + "license": "MIT", "dependencies": { "escalade": "^3.2.0", "picocolors": "^1.1.1" @@ -6847,6 +7492,7 @@ "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "punycode": "^2.1.0" } @@ -6855,13 +7501,16 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/uuid": { "version": "8.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "deprecated": "uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).", "dev": true, + "license": "MIT", "bin": { "uuid": "dist/bin/uuid" } @@ -6870,13 +7519,15 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", "dev": true, + "license": "Apache-2.0", "dependencies": { "spdx-correct": "^3.0.0", "spdx-expression-parse": "^3.0.0" @@ -6886,13 +7537,15 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/walk-up-path/-/walk-up-path-3.0.1.tgz", "integrity": "sha512-9YlCL/ynK3CTlrSRrDxZvUauLzAswPCrsaCgilqFevUYpeEW0/3ScEjaa3kbW/T0ghhkEr7mv+fpjqn1Y1YuTA==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/walkdir": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/walkdir/-/walkdir-0.4.1.tgz", "integrity": "sha512-3eBwRyEln6E1MSzcxcVpQIhRG8Q1jLvEqRmCZqS3dsfXEDR/AhOF4d+jHg1qvDCpYaVRZjENPQyrVxAkQqxPgQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6.0.0" } @@ -6902,6 +7555,7 @@ "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", "dev": true, + "license": "MIT", "engines": { "node": ">= 8" } @@ -6910,13 +7564,15 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "dev": true + "dev": true, + "license": "BSD-2-Clause" }, "node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", "dev": true, + "license": "MIT", "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -6927,6 +7583,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, + "license": "ISC", "dependencies": { "isexe": "^2.0.0" }, @@ -6941,6 +7598,7 @@ "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -6949,13 +7607,15 @@ "version": "9.3.2", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-9.3.2.tgz", "integrity": "sha512-Xz4Nm9c+LiBHhDR5bDLnNzmj6+5F+cyEAWPMkbs2awq/dYazR/efelZzUAjB/y3kNHL+uzkHvxVVpaOfGCPV7A==", - "dev": true + "dev": true, + "license": "Apache-2.0" }, "node_modules/wrap-ansi": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", "dev": true, + "license": "MIT", "dependencies": { "ansi-styles": "^6.1.0", "string-width": "^5.0.1", @@ -6974,6 +7634,7 @@ "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dev": true, + "license": "MIT", "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", @@ -6991,6 +7652,7 @@ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", "dev": true, + "license": "MIT", "engines": { "node": ">=12" }, @@ -7003,6 +7665,7 @@ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", "dev": true, + "license": "MIT", "engines": { "node": ">=12" }, @@ -7014,13 +7677,15 @@ "version": "9.2.2", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/wrap-ansi/node_modules/string-width": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", "dev": true, + "license": "MIT", "dependencies": { "eastasianwidth": "^0.2.0", "emoji-regex": "^9.2.2", @@ -7038,6 +7703,7 @@ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", "dev": true, + "license": "MIT", "dependencies": { "ansi-regex": "^6.0.1" }, @@ -7051,13 +7717,15 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" }, "node_modules/write-file-atomic": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-4.0.2.tgz", "integrity": "sha512-7KxauUdBmSdWnmpaGFg+ppNjKF8uNLry8LyzjauQDOVONfFLNKrKvQOxZ/VuTIcS/gge/YNahf5RIIQWTSarlg==", "dev": true, + "license": "ISC", "dependencies": { "imurmurhash": "^0.1.4", "signal-exit": "^3.0.7" @@ -7069,13 +7737,15 @@ "node_modules/xmlcreate": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.4.tgz", - "integrity": "sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg==" + "integrity": "sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg==", + "license": "Apache-2.0" }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.4" } @@ -7084,6 +7754,7 @@ "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "license": "ISC", "engines": { "node": ">=10" } @@ -7092,12 +7763,14 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "license": "MIT", "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", @@ -7116,6 +7789,7 @@ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", "dev": true, + "license": "ISC", "engines": { "node": ">=10" } @@ -7125,6 +7799,7 @@ "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, + "license": "MIT", "dependencies": { "camelcase": "^6.0.0", "decamelize": "^4.0.0", @@ -7140,6 +7815,7 @@ "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -7152,6 +7828,7 @@ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -7164,6 +7841,7 @@ "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -7172,6 +7850,7 @@ "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "license": "ISC", "engines": { "node": ">=12" } @@ -7181,6 +7860,7 @@ "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -7190,6 +7870,7 @@ "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, diff --git a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/package.json b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/package.json index 1b1007c6b329..e69e0482f651 100644 --- a/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/package.json +++ b/core/generator/gapic-generator-typescript/templates/cjs/typescript_gapic/package.json @@ -31,7 +31,7 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", + "system-test": "echo 'no system tests'", "test": "c8 mocha build/test" }, "dependencies": { @@ -48,7 +48,6 @@ "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", "typescript": "5.8.3", "sinon": "^20.0.0" }, diff --git a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/package.json b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/package.json index 67eb93b22220..8a457bd066d1 100644 --- a/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/package.json +++ b/core/generator/gapic-generator-typescript/templates/esm/typescript_gapic/package.json @@ -61,9 +61,7 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", + "system-test": "echo 'no system tests'", "test:cjs": "c8 mocha build/cjs/test", "test:esm": "c8 mocha build/esm/test", "test": "npm run test:cjs && npm run test:esm", @@ -94,7 +92,6 @@ "long": "^5.3.2", "mocha": "^11.7.4", "typescript": "5.8.3", - "pack-n-play": "^4.2.1", "sinon": "^20.0.0", "ts-loader": "^8.4.0", "webpack": "^5.102.1", diff --git a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v1-nodejs/package.json b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v1-nodejs/package.json index 0e2a0b9dc391..ff7555d2dfdb 100644 --- a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v1-nodejs/package.json +++ b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v1-nodejs/package.json @@ -32,7 +32,7 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", + "system-test": "echo 'no system test'", "test": "c8 mocha build/test" }, "dependencies": { @@ -49,7 +49,6 @@ "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", "typescript": "5.8.3", "sinon": "^21.0.0" }, diff --git a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v1p1beta1-nodejs/package.json b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v1p1beta1-nodejs/package.json index 0e2a0b9dc391..ff7555d2dfdb 100644 --- a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v1p1beta1-nodejs/package.json +++ b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v1p1beta1-nodejs/package.json @@ -32,7 +32,7 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", + "system-test": "echo 'no system test'", "test": "c8 mocha build/test" }, "dependencies": { @@ -49,7 +49,6 @@ "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", "typescript": "5.8.3", "sinon": "^21.0.0" }, diff --git a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v2-nodejs/package.json b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v2-nodejs/package.json index 70f69f94570a..bac25176e1bc 100644 --- a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v2-nodejs/package.json +++ b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech-nodejs/speech-v2-nodejs/package.json @@ -31,7 +31,7 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", + "system-test": "echo 'no system test'", "test": "c8 mocha build/test" }, "dependencies": { @@ -48,7 +48,6 @@ "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", "typescript": "5.8.3", "sinon": "^21.0.0" }, diff --git a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech/package.json b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech/package.json index 0e2a0b9dc391..ff7555d2dfdb 100644 --- a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech/package.json +++ b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-speech/package.json @@ -32,7 +32,7 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", + "system-test": "echo 'no system test'", "test": "c8 mocha build/test" }, "dependencies": { @@ -49,7 +49,6 @@ "jsdoc-fresh": "^5.0.2", "jsdoc-region-tag": "^4.0.1", "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", "typescript": "5.8.3", "sinon": "^21.0.0" }, diff --git a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-tasks-nodejs/tasks-v2-nodejs/package.json b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-tasks-nodejs/tasks-v2-nodejs/package.json index 40bd36b0092a..88e6cafc5736 100644 --- a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-tasks-nodejs/tasks-v2-nodejs/package.json +++ b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-tasks-nodejs/tasks-v2-nodejs/package.json @@ -60,9 +60,7 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", + "system-test": "echo 'no system test'", "test:cjs": "c8 mocha build/cjs/test", "test:esm": "c8 mocha build/esm/test", "test": "npm run test:cjs && npm run test:esm", @@ -92,7 +90,6 @@ "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", "typescript": "5.8.3", "sinon": "^21.0.0", "ts-loader": "^8.4.0", diff --git a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-tasks-nodejs/tasks-v2beta2-nodejs/package.json b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-tasks-nodejs/tasks-v2beta2-nodejs/package.json index 40bd36b0092a..88e6cafc5736 100644 --- a/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-tasks-nodejs/tasks-v2beta2-nodejs/package.json +++ b/core/generator/gapic-generator-typescript/test-fixtures/google-cloud-tasks-nodejs/tasks-v2beta2-nodejs/package.json @@ -60,9 +60,7 @@ "fix": "gts fix", "lint": "gts check", "prepare": "npm run compile-protos && npm run compile", - "system-test:cjs": "c8 mocha build/cjs/system-test", - "system-test:esm": "c8 mocha build/esm/system-test", - "system-test": "npm run system-test:esm && npm run system-test:cjs", + "system-test": "echo 'no system test'", "test:cjs": "c8 mocha build/cjs/test", "test:esm": "c8 mocha build/esm/test", "test": "npm run test:cjs && npm run test:esm", @@ -92,7 +90,6 @@ "jsdoc-fresh": "^5.0.2", "long": "^5.3.2", "mocha": "^11.7.4", - "pack-n-play": "^4.2.1", "typescript": "5.8.3", "sinon": "^21.0.0", "ts-loader": "^8.4.0", diff --git a/core/generator/gapic-generator-typescript/yarn.lock b/core/generator/gapic-generator-typescript/yarn.lock index 5dc992012238..36b587c831a2 100644 --- a/core/generator/gapic-generator-typescript/yarn.lock +++ b/core/generator/gapic-generator-typescript/yarn.lock @@ -24,7 +24,7 @@ resolved "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.8.tgz" integrity sha512-oH5UPLMWR3L2wEFLnFJ1TZXqHufiTKAiLfqw5zkhS4dKXLJ10yVztfil/twG8EDTA4F/tvVNw9nOl4ZMslB8rQ== -"@babel/core@^7.26.8": +"@babel/core@^7.0.0", "@babel/core@^7.26.8": version "7.26.10" resolved "https://registry.npmjs.org/@babel/core/-/core-7.26.10.tgz" integrity sha512-vMqyb7XCDMPvJFFOaT9kxtiRh42GwlZEg1/uIgtZshS5a/8OaduUfCi7kynKgc3Tw/6Uo2D+db9qBttghhmxwQ== @@ -208,7 +208,7 @@ "@google-cloud/storage@^7.15.2": version "7.19.0" - resolved "https://registry.yarnpkg.com/@google-cloud/storage/-/storage-7.19.0.tgz#34fb7cc4eacede5a2f1f0d6cefa0c70a22078c5b" + resolved "https://registry.npmjs.org/@google-cloud/storage/-/storage-7.19.0.tgz" integrity sha512-n2FjE7NAOYyshogdc7KQOl/VZb4sneqPjWouSyia9CMDdMhRX5+RIbqalNmC7LOLzuLAN89VlF2HvG8na9G+zQ== dependencies: "@google-cloud/paginator" "^5.0.0" @@ -310,14 +310,6 @@ resolved "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz" integrity sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ== -"@jridgewell/trace-mapping@0.3.9": - version "0.3.9" - resolved "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz" - integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== - dependencies: - "@jridgewell/resolve-uri" "^3.0.3" - "@jridgewell/sourcemap-codec" "^1.4.10" - "@jridgewell/trace-mapping@^0.3.24", "@jridgewell/trace-mapping@^0.3.25": version "0.3.25" resolved "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz" @@ -326,6 +318,14 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" +"@jridgewell/trace-mapping@0.3.9": + version "0.3.9" + resolved "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz" + integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== + dependencies: + "@jridgewell/resolve-uri" "^3.0.3" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@js-sdsl/ordered-map@^4.4.2": version "4.4.2" resolved "https://registry.npmjs.org/@js-sdsl/ordered-map/-/ordered-map-4.4.2.tgz" @@ -340,7 +340,7 @@ "@nodable/entities@^2.1.0": version "2.1.0" - resolved "https://registry.yarnpkg.com/@nodable/entities/-/entities-2.1.0.tgz#f543e5c6446720d4cf9e498a83019dd159973bc2" + resolved "https://registry.npmjs.org/@nodable/entities/-/entities-2.1.0.tgz" integrity sha512-nyT7T3nbMyBI/lvr6L5TyWbFJAI9FTgVRakNoBqCD+PmID8DzFrrNdLLtHMwMszOtqZa8PAOV24ZqDnQrhQINA== "@nodelib/fs.scandir@2.1.5": @@ -351,7 +351,7 @@ "@nodelib/fs.stat" "2.0.5" run-parallel "^1.1.9" -"@nodelib/fs.stat@2.0.5", "@nodelib/fs.stat@^2.0.2": +"@nodelib/fs.stat@^2.0.2", "@nodelib/fs.stat@2.0.5": version "2.0.5" resolved "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz" integrity sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A== @@ -369,7 +369,7 @@ resolved "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz" integrity sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA== -"@octokit/core@^5.0.2": +"@octokit/core@^5", "@octokit/core@^5.0.2", "@octokit/core@5": version "5.2.2" resolved "https://registry.npmjs.org/@octokit/core/-/core-5.2.2.tgz" integrity sha512-/g2d4sW9nUDJOMz3mabVQvOGhVa4e/BN/Um7yca9Bb2XTzPPnfTWHWQg+IsEYO7M3Vx+EXvaM/I2pJWIMun1bg== @@ -574,7 +574,7 @@ dependencies: long "*" -"@types/markdown-it@^14.1.1": +"@types/markdown-it@*", "@types/markdown-it@^14.1.1": version "14.1.2" resolved "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.1.2.tgz" integrity sha512-promo4eFwuiW+TfGxhi+0x3czqTYJkG8qB17ZUJiVF10Xm7NLVRSLUsfRTU/6h1e24VvRnXCx+hG7li58lkzog== @@ -602,7 +602,7 @@ resolved "https://registry.npmjs.org/@types/module-alias/-/module-alias-2.0.4.tgz" integrity sha512-5+G/QXO/DvHZw60FjvbDzO4JmlD/nG5m2/vVGt25VN1eeP3w2bCoks1Wa7VuptMPM1TxJdx6RjO70N9Fw0nZPA== -"@types/node@*", "@types/node@>=13.7.0", "@types/node@^22.18.12": +"@types/node@*", "@types/node@^22.18.12", "@types/node@>=13.7.0": version "22.18.12" resolved "https://registry.npmjs.org/@types/node/-/node-22.18.12.tgz" integrity sha512-BICHQ67iqxQGFSzfCFTT7MRQ5XcBjG5aeKh5Ok38UBbPe5fxTyE+aHFxwVrGyr8GNlqFMLKD1D3P2K/1ks8tog== @@ -672,7 +672,7 @@ semver "^7.3.7" tsutils "^3.21.0" -"@typescript-eslint/parser@5.62.0": +"@typescript-eslint/parser@^5.0.0", "@typescript-eslint/parser@5.62.0": version "5.62.0" resolved "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.62.0.tgz" integrity sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA== @@ -779,11 +779,26 @@ acorn@^5.0.0: resolved "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz" integrity sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg== -acorn@^8.11.0, acorn@^8.4.1, acorn@^8.9.0: +"acorn@^6.0.0 || ^7.0.0 || ^8.0.0", acorn@^8.9.0: + version "8.14.1" + resolved "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz" + integrity sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg== + +acorn@^8.11.0: + version "8.14.1" + resolved "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz" + integrity sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg== + +acorn@^8.4.1: version "8.14.1" resolved "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz" integrity sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg== +agent-base@^7.1.2: + version "7.1.3" + resolved "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz" + integrity sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw== + agent-base@6: version "6.0.2" resolved "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz" @@ -791,11 +806,6 @@ agent-base@6: dependencies: debug "4" -agent-base@^7.1.2: - version "7.1.3" - resolved "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz" - integrity sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw== - ajv@^6.12.4: version "6.12.6" resolved "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz" @@ -840,6 +850,14 @@ ansi-styles@^6.1.0: resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz" integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug== +anymatch@~3.1.2: + version "3.1.3" + resolved "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz" + integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw== + dependencies: + normalize-path "^3.0.0" + picomatch "^2.0.4" + arg@^4.1.0: version "4.1.3" resolved "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz" @@ -907,6 +925,11 @@ bignumber.js@^9.0.0: resolved "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.3.0.tgz" integrity sha512-EM7aMFTXbptt/wZdMlBv2t8IViwQL+h6SLHosp8Yf0dqJMTnY6iL32opnAB6kAdL0SZPuvcAzFr31o0c/R3/RA== +binary-extensions@^2.0.0: + version "2.3.0" + resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz" + integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw== + bluebird@^3.7.2: version "3.7.2" resolved "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz" @@ -914,7 +937,7 @@ bluebird@^3.7.2: brace-expansion@^1.1.7: version "1.1.13" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.13.tgz#d37875c01dc9eff988dd49d112a57cb67b54efe6" + resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.13.tgz" integrity sha512-9ZLprWS6EENmhEOpjCYW2c8VkmOvckIJZfkr7rBW6dObmfgJ/L1GpSYW5Hpo9lDz4D1+n0Ckz8rU7FwHDQiG/w== dependencies: balanced-match "^1.0.0" @@ -922,12 +945,12 @@ brace-expansion@^1.1.7: brace-expansion@^2.0.1, brace-expansion@^2.0.2: version "2.0.3" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.3.tgz#0493338bdd58e319b1039c67cf7ee439892c01d9" + resolved "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.3.tgz" integrity sha512-MCV/fYJEbqx68aE58kv2cA/kiky1G8vux3OR6/jbS+jIMe/6fJWa0DTzJU7dqijOWYwHi1t29FlfYI9uytqlpA== dependencies: balanced-match "^1.0.0" -braces@^3.0.3: +braces@^3.0.3, braces@~3.0.2: version "3.0.3" resolved "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz" integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== @@ -939,7 +962,7 @@ browser-stdout@^1.3.1: resolved "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz" integrity sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw== -browserslist@^4.24.0: +browserslist@^4.24.0, "browserslist@>= 4.21.0": version "4.24.4" resolved "https://registry.npmjs.org/browserslist/-/browserslist-4.24.4.tgz" integrity sha512-KDi1Ny1gSePi1vm0q4oxSF8b4DR44GF4BbmS2YdhPLOEqd8pDviZOGH/GsmRwoWJ2+5Lr085X7naowMwKHDG1A== @@ -951,7 +974,7 @@ browserslist@^4.24.0: buffer-equal-constant-time@^1.0.1: version "1.0.1" - resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819" + resolved "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz" integrity sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA== buffer-from@^1.0.0: @@ -1051,6 +1074,21 @@ chardet@^0.7.0: resolved "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz" integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== +chokidar@^3.3.0: + version "3.6.0" + resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz" + integrity sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw== + dependencies: + anymatch "~3.1.2" + braces "~3.0.2" + glob-parent "~5.1.2" + is-binary-path "~2.1.0" + is-glob "~4.0.1" + normalize-path "~3.0.0" + readdirp "~3.6.0" + optionalDependencies: + fsevents "~2.3.2" + chokidar@^4.0.1: version "4.0.3" resolved "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz" @@ -1137,7 +1175,7 @@ cross-spawn@^7.0.2, cross-spawn@^7.0.3, cross-spawn@^7.0.6: shebang-command "^2.0.0" which "^2.0.1" -d@1, d@^1.0.1, d@^1.0.2: +d@^1.0.1, d@^1.0.2, d@1: version "1.0.2" resolved "https://registry.npmjs.org/d/-/d-1.0.2.tgz" integrity sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw== @@ -1150,7 +1188,7 @@ data-uri-to-buffer@^4.0.0: resolved "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz" integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A== -debug@4, debug@^4.1.0, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4, debug@^4.3.5: +debug@^4.1.0, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4, debug@^4.3.5, debug@4: version "4.4.0" resolved "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz" integrity sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA== @@ -1268,7 +1306,7 @@ eastasianwidth@^0.2.0: resolved "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz" integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA== -ecdsa-sig-formatter@1.0.11, ecdsa-sig-formatter@^1.0.11: +ecdsa-sig-formatter@^1.0.11, ecdsa-sig-formatter@1.0.11: version "1.0.11" resolved "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz" integrity sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ== @@ -1454,7 +1492,7 @@ escope@^3.3.0: esrecurse "^4.1.0" estraverse "^4.1.1" -eslint-config-prettier@9.1.0: +eslint-config-prettier@*, eslint-config-prettier@9.1.0: version "9.1.0" resolved "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz" integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== @@ -1534,7 +1572,7 @@ eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4 resolved "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz" integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== -eslint@8.57.1: +eslint@*, "eslint@^6.0.0 || ^7.0.0 || ^8.0.0", "eslint@^6.0.0 || ^7.0.0 || >=8.0.0", eslint@>=4.19.1, eslint@>=5, eslint@>=7.0.0, eslint@>=8.0.0, eslint@8.57.1: version "8.57.1" resolved "https://registry.npmjs.org/eslint/-/eslint-8.57.1.tgz" integrity sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA== @@ -1685,7 +1723,12 @@ estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0: resolved "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz" integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== -estraverse@^5.1.0, estraverse@^5.2.0: +estraverse@^5.1.0: + version "5.3.0" + resolved "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz" + integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA== + +estraverse@^5.2.0: version "5.3.0" resolved "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz" integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA== @@ -1777,14 +1820,14 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: fast-xml-builder@^1.1.5: version "1.1.5" - resolved "https://registry.yarnpkg.com/fast-xml-builder/-/fast-xml-builder-1.1.5.tgz#50188e1452a5fa095f415d3e63dcac0a1dbcbf11" + resolved "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.1.5.tgz" integrity sha512-4TJn/8FKLeslLAH3dnohXqE3QSoxkhvaMzepOIZytwJXZO69Bfz0HBdDHzOTOon6G59Zrk6VQ2bEiv1t61rfkA== dependencies: path-expression-matcher "^1.1.3" fast-xml-parser@^5.3.4: version "5.7.1" - resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-5.7.1.tgz#17697550bdd2a0a0d47cdc4b456c009c4cbe8a06" + resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.7.1.tgz" integrity sha512-8Cc3f8GUGUULg34pBch/KGyPLglS+OFs05deyOlY7fL2MTagYPKrVQNmR1fLF/yJ9PH5ZSTd3YDF6pnmeZU+zA== dependencies: "@nodable/entities" "^2.1.0" @@ -1860,7 +1903,7 @@ flat@^5.0.2: flatted@^3.2.9: version "3.4.2" - resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.4.2.tgz#f5c23c107f0f37de8dbdf24f13722b3b98d52726" + resolved "https://registry.npmjs.org/flatted/-/flatted-3.4.2.tgz" integrity sha512-PjDse7RzhcPkIJwy5t7KPWQSZ9cAbzQXcafsetQoD7sOJRQlGikNbx7yZp2OotDnJyrDcbyRq3Ttb18iYOqkxA== foreground-child@^3.1.0: @@ -1941,19 +1984,19 @@ gaxios@^6.0.0, gaxios@^6.0.2, gaxios@^6.1.1: node-fetch "^2.6.9" uuid "^9.0.1" -gaxios@^7.0.0: - version "7.1.1" - resolved "https://registry.npmjs.org/gaxios/-/gaxios-7.1.1.tgz" - integrity sha512-Odju3uBUJyVCkW64nLD4wKLhbh93bh6vIg/ZIXkWiLPBrdgtc65+tls/qml+un3pr6JqYVFDZbbmLDQT68rTOQ== +gaxios@^7.0.0-rc.1, gaxios@^7.0.0-rc.4: + version "7.0.0-rc.5" + resolved "https://registry.npmjs.org/gaxios/-/gaxios-7.0.0-rc.5.tgz" + integrity sha512-s9rlpplwdb/KCq2DYevVTM/MpozeVZuR3pkzDGXtRhY7wD4fXftIYXUAerX07ZPB3J8/dHUJsX7fPnN2O4Psuw== dependencies: extend "^3.0.2" https-proxy-agent "^7.0.1" node-fetch "^3.3.2" -gaxios@^7.0.0-rc.1, gaxios@^7.0.0-rc.4: - version "7.0.0-rc.5" - resolved "https://registry.npmjs.org/gaxios/-/gaxios-7.0.0-rc.5.tgz" - integrity sha512-s9rlpplwdb/KCq2DYevVTM/MpozeVZuR3pkzDGXtRhY7wD4fXftIYXUAerX07ZPB3J8/dHUJsX7fPnN2O4Psuw== +gaxios@^7.0.0: + version "7.1.1" + resolved "https://registry.npmjs.org/gaxios/-/gaxios-7.1.1.tgz" + integrity sha512-Odju3uBUJyVCkW64nLD4wKLhbh93bh6vIg/ZIXkWiLPBrdgtc65+tls/qml+un3pr6JqYVFDZbbmLDQT68rTOQ== dependencies: extend "^3.0.2" https-proxy-agent "^7.0.1" @@ -1968,15 +2011,6 @@ gcp-metadata@^6.1.0: google-logging-utils "^0.0.2" json-bigint "^1.0.0" -gcp-metadata@^7.0.0: - version "7.0.1" - resolved "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-7.0.1.tgz" - integrity sha512-UcO3kefx6dCcZkgcTGgVOTFb7b1LlQ02hY1omMjjrrBzkajRMCFgYOjs7J71WqnuG1k2b+9ppGL7FsOfhZMQKQ== - dependencies: - gaxios "^7.0.0" - google-logging-utils "^1.0.0" - json-bigint "^1.0.0" - gcp-metadata@^7.0.0-rc.1: version "7.0.0-rc.1" resolved "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-7.0.0-rc.1.tgz" @@ -1986,6 +2020,15 @@ gcp-metadata@^7.0.0-rc.1: google-logging-utils "^1.0.0" json-bigint "^1.0.0" +gcp-metadata@^7.0.0: + version "7.0.1" + resolved "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-7.0.1.tgz" + integrity sha512-UcO3kefx6dCcZkgcTGgVOTFb7b1LlQ02hY1omMjjrrBzkajRMCFgYOjs7J71WqnuG1k2b+9ppGL7FsOfhZMQKQ== + dependencies: + gaxios "^7.0.0" + google-logging-utils "^1.0.0" + json-bigint "^1.0.0" + gensync@^1.0.0-beta.2: version "1.0.0-beta.2" resolved "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz" @@ -2039,9 +2082,16 @@ glob-parent@^6.0.2: dependencies: is-glob "^4.0.3" +glob-parent@~5.1.2: + version "5.1.2" + resolved "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz" + integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== + dependencies: + is-glob "^4.0.1" + glob@^10.4.5: version "10.5.0" - resolved "https://registry.yarnpkg.com/glob/-/glob-10.5.0.tgz#8ec0355919cd3338c28428a23d4f24ecc5fe738c" + resolved "https://registry.npmjs.org/glob/-/glob-10.5.0.tgz" integrity sha512-DfXN8DfhJ7NH3Oe7cFmu3NCu1wKbkReJ8TorzSAFbSKrlNaQSKfIzqYqVY8zlbs2NLBbWpRiU52GX2PbaBVNkg== dependencies: foreground-child "^3.1.0" @@ -2053,7 +2103,7 @@ glob@^10.4.5: glob@^7.1.3: version "7.2.3" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" + resolved "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz" integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q== dependencies: fs.realpath "^1.0.0" @@ -2065,7 +2115,7 @@ glob@^7.1.3: glob@^8.0.0: version "8.1.0" - resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e" + resolved "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz" integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ== dependencies: fs.realpath "^1.0.0" @@ -2212,14 +2262,6 @@ gtoken@^7.0.0: gaxios "^6.0.0" jws "^4.0.0" -gtoken@^8.0.0: - version "8.0.0" - resolved "https://registry.npmjs.org/gtoken/-/gtoken-8.0.0.tgz" - integrity sha512-+CqsMbHPiSTdtSO14O51eMNlrp9N79gmeqmXeouJOhfucAedHw9noVe/n5uJk3tbKE6a+6ZCQg3RPhVhHByAIw== - dependencies: - gaxios "^7.0.0" - jws "^4.0.0" - gtoken@^8.0.0-rc.1: version "8.0.0-rc.1" resolved "https://registry.npmjs.org/gtoken/-/gtoken-8.0.0-rc.1.tgz" @@ -2228,6 +2270,14 @@ gtoken@^8.0.0-rc.1: gaxios "^7.0.0-rc.1" jws "^4.0.0" +gtoken@^8.0.0: + version "8.0.0" + resolved "https://registry.npmjs.org/gtoken/-/gtoken-8.0.0.tgz" + integrity sha512-+CqsMbHPiSTdtSO14O51eMNlrp9N79gmeqmXeouJOhfucAedHw9noVe/n5uJk3tbKE6a+6ZCQg3RPhVhHByAIw== + dependencies: + gaxios "^7.0.0" + jws "^4.0.0" + gts@^6.0.2: version "6.0.2" resolved "https://registry.npmjs.org/gts/-/gts-6.0.2.tgz" @@ -2375,7 +2425,7 @@ inflight@^1.0.4: once "^1.3.0" wrappy "1" -inherits@2, inherits@^2.0.3: +inherits@^2.0.3, inherits@2: version "2.0.4" resolved "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== @@ -2412,6 +2462,13 @@ is-arrayish@^0.2.1: resolved "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz" integrity sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg== +is-binary-path@~2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz" + integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== + dependencies: + binary-extensions "^2.0.0" + is-core-module@^2.11.0, is-core-module@^2.16.0, is-core-module@^2.5.0: version "2.16.1" resolved "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz" @@ -2437,7 +2494,7 @@ is-fullwidth-code-point@^3.0.0: resolved "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz" integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== -is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3: +is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3, is-glob@~4.0.1: version "4.0.3" resolved "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz" integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== @@ -2510,7 +2567,7 @@ js-tokens@^4.0.0: js-yaml@^4.1.0, js-yaml@^4.1.1: version "4.1.1" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.1.tgz#854c292467705b699476e1a2decc0c8a3458806b" + resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz" integrity sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA== dependencies: argparse "^2.0.1" @@ -2582,7 +2639,7 @@ json5@^2.1.3, json5@^2.2.3: jwa@^2.0.1: version "2.0.1" - resolved "https://registry.yarnpkg.com/jwa/-/jwa-2.0.1.tgz#bf8176d1ad0cd72e0f3f58338595a13e110bc804" + resolved "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz" integrity sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg== dependencies: buffer-equal-constant-time "^1.0.1" @@ -2591,7 +2648,7 @@ jwa@^2.0.1: jws@^4.0.0: version "4.0.1" - resolved "https://registry.yarnpkg.com/jws/-/jws-4.0.1.tgz#07edc1be8fac20e677b283ece261498bd38f0690" + resolved "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz" integrity sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA== dependencies: jwa "^2.0.1" @@ -2670,7 +2727,7 @@ lodash.merge@^4.6.2: lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.21: version "4.18.1" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.18.1.tgz#ff2b66c1f6326d59513de2407bf881439812771c" + resolved "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz" integrity sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q== log-symbols@^4.1.0: @@ -2725,9 +2782,9 @@ markdown-it-anchor@^8.6.7: resolved "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-8.6.7.tgz" integrity sha512-FlCHFwNnutLgVTflOYHPW2pPcl2AACqVzExlkGQNsi4CJgqOHN7YTgDd4LuhgN1BFO3TS0vLAruV1Td6dwWPJA== -markdown-it@^14.1.0: +markdown-it@*, markdown-it@^14.1.0: version "14.1.1" - resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-14.1.1.tgz#856f90b66fc39ae70affd25c1b18b581d7deee1f" + resolved "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.1.tgz" integrity sha512-BuU2qnTti9YKgK5N+IeMubp14ZUKUUw7yeJbkjtosvHiP0AZ5c8IAgEMk79D0eC8F23r4Ac/q8cAIFdm2FtyoA== dependencies: argparse "^2.0.1" @@ -2822,23 +2879,44 @@ min-indent@^1.0.0: resolved "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz" integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg== -minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: +minimatch@^3.0.5: + version "3.1.5" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz" + integrity sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w== + dependencies: + brace-expansion "^1.1.7" + +minimatch@^3.1.1: + version "3.1.5" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz" + integrity sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w== + dependencies: + brace-expansion "^1.1.7" + +minimatch@^3.1.2: version "3.1.5" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.5.tgz#580c88f8d5445f2bd6aa8f3cadefa0de79fbd69e" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz" integrity sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w== dependencies: brace-expansion "^1.1.7" minimatch@^5.0.1, minimatch@^5.1.0: version "5.1.9" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.9.tgz#1293ef15db0098b394540e8f9f744f9fda8dee4b" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-5.1.9.tgz" integrity sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw== dependencies: brace-expansion "^2.0.1" -minimatch@^9.0.4, minimatch@^9.0.5: +minimatch@^9.0.4: version "9.0.9" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.9.tgz#9b0cb9fcb78087f6fd7eababe2511c4d3d60574e" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz" + integrity sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg== + dependencies: + brace-expansion "^2.0.2" + +minimatch@^9.0.5: + version "9.0.9" + resolved "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz" integrity sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg== dependencies: brace-expansion "^2.0.2" @@ -2977,6 +3055,11 @@ normalize-package-data@^3.0.0: semver "^7.3.4" validate-npm-package-license "^3.0.1" +normalize-path@^3.0.0, normalize-path@~3.0.0: + version "3.0.0" + resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz" + integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== + npm-run-path@^4.0.1: version "4.0.1" resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz" @@ -3114,14 +3197,9 @@ path-exists@^4.0.0: resolved "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz" integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== -path-expression-matcher@^1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/path-expression-matcher/-/path-expression-matcher-1.1.3.tgz#8bf7c629dc1b114e42b633c071f06d14625b4e0d" - integrity sha512-qdVgY8KXmVdJZRSS1JdEPOKPdTiEK/pi0RkcT2sw1RhXxohdujUlJFPuS1TSkevZ9vzd3ZlL7ULl1MHGTApKzQ== - -path-expression-matcher@^1.5.0: +path-expression-matcher@^1.1.3, path-expression-matcher@^1.5.0: version "1.5.0" - resolved "https://registry.yarnpkg.com/path-expression-matcher/-/path-expression-matcher-1.5.0.tgz#3b98545dc88ffebb593e2d8458d0929da9275f4a" + resolved "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.5.0.tgz" integrity sha512-cbrerZV+6rvdQrrD+iGMcZFEiiSrbv9Tfdkvnusy6y0x0GKBXREFg/Y65GhIfm0tnLntThhzCnfKwp1WRjeCyQ== path-is-absolute@^1.0.0: @@ -3157,9 +3235,9 @@ picocolors@^1.0.0, picocolors@^1.1.1: resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz" integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA== -picomatch@^2.3.1: +picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1: version "2.3.2" - resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.2.tgz#5a942915e26b372dc0f0e6753149a16e6b1c5601" + resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz" integrity sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA== prelude-ls@^1.2.1: @@ -3179,7 +3257,7 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@3.3.3: +prettier@>=3.0.0, prettier@3.3.3: version "3.3.3" resolved "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz" integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew== @@ -3207,10 +3285,10 @@ protobufjs-cli@^1.2.0: tmp "^0.2.1" uglify-js "^3.7.7" -protobufjs@7.5.4: - version "7.5.4" - resolved "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.4.tgz" - integrity sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg== +protobufjs@^7.0.0, protobufjs@^7.2.5, protobufjs@^7.4.0, protobufjs@^7.5.3, protobufjs@^7.5.5: + version "7.5.5" + resolved "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.5.tgz" + integrity sha512-3wY1AxV+VBNW8Yypfd1yQY9pXnqTAN+KwQxL8iYm3/BjKYMNg4i0owhEe26PWDOMaIrzeeF98Lqd5NGz4omiIg== dependencies: "@protobufjs/aspromise" "^1.1.2" "@protobufjs/base64" "^1.1.2" @@ -3225,10 +3303,10 @@ protobufjs@7.5.4: "@types/node" ">=13.7.0" long "^5.0.0" -protobufjs@^7.2.5, protobufjs@^7.4.0, protobufjs@^7.5.3, protobufjs@^7.5.5: - version "7.5.5" - resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.5.5.tgz#b7089ca4410374c75150baf277353ef76db69f96" - integrity sha512-3wY1AxV+VBNW8Yypfd1yQY9pXnqTAN+KwQxL8iYm3/BjKYMNg4i0owhEe26PWDOMaIrzeeF98Lqd5NGz4omiIg== +protobufjs@7.5.4: + version "7.5.4" + resolved "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.4.tgz" + integrity sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg== dependencies: "@protobufjs/aspromise" "^1.1.2" "@protobufjs/base64" "^1.1.2" @@ -3303,6 +3381,13 @@ readdirp@^4.0.1: resolved "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz" integrity sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg== +readdirp@~3.6.0: + version "3.6.0" + resolved "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz" + integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA== + dependencies: + picomatch "^2.2.1" + redent@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz" @@ -3389,7 +3474,7 @@ reusify@^1.0.4: resolved "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz" integrity sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw== -rimraf@3.0.2, rimraf@^3.0.2: +rimraf@^3.0.2, rimraf@3.0.2: version "3.0.2" resolved "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz" integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== @@ -3425,21 +3510,41 @@ safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.2.1, safe-buffer@~5.2.0: resolved "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz" integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== -"semver@2 || 3 || 4 || 5": - version "5.7.2" - resolved "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz" - integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== - semver@^6.3.1: version "6.3.1" resolved "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== -semver@^7.0.0, semver@^7.1.2, semver@^7.3.4, semver@^7.3.7, semver@^7.3.8: +semver@^7.0.0: + version "7.7.1" + resolved "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz" + integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA== + +semver@^7.1.2: + version "7.7.1" + resolved "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz" + integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA== + +semver@^7.3.4: version "7.7.1" resolved "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz" integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA== +semver@^7.3.7: + version "7.7.1" + resolved "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz" + integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA== + +semver@^7.3.8: + version "7.7.1" + resolved "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz" + integrity sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA== + +"semver@2 || 3 || 4 || 5": + version "5.7.2" + resolved "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz" + integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== + serialize-javascript@^6.0.2: version "6.0.2" resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz" @@ -3559,6 +3664,13 @@ stream-shift@^1.0.2: resolved "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.3.tgz" integrity sha512-76ORR0DO1o1hlKwTbi/DM3EXWGf3ZJYO8cXX5RJwnul2DEg2oyoZyjLNoQM8WsvZiFKCRfC1O0J7iCvie3RZmQ== +string_decoder@^1.1.1: + version "1.3.0" + resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz" + integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== + dependencies: + safe-buffer "~5.2.0" + "string-width-cjs@npm:string-width@^4.2.0": version "4.2.3" resolved "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz" @@ -3577,7 +3689,7 @@ string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" -string-width@^5.0.1, string-width@^5.1.2: +string-width@^5.0.1: version "5.1.2" resolved "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz" integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== @@ -3586,12 +3698,14 @@ string-width@^5.0.1, string-width@^5.1.2: emoji-regex "^9.2.2" strip-ansi "^7.0.1" -string_decoder@^1.1.1: - version "1.3.0" - resolved "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz" - integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== +string-width@^5.1.2: + version "5.1.2" + resolved "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz" + integrity sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA== dependencies: - safe-buffer "~5.2.0" + eastasianwidth "^0.2.0" + emoji-regex "^9.2.2" + strip-ansi "^7.0.1" "strip-ansi-cjs@npm:strip-ansi@^6.0.1": version "6.0.1" @@ -3633,7 +3747,7 @@ strip-json-comments@^3.1.0, strip-json-comments@^3.1.1: strnum@^2.2.3: version "2.2.3" - resolved "https://registry.yarnpkg.com/strnum/-/strnum-2.2.3.tgz#0119fce02749a11bb126a4d686ac5dbdf6e57586" + resolved "https://registry.npmjs.org/strnum/-/strnum-2.2.3.tgz" integrity sha512-oKx6RUCuHfT3oyVjtnrmn19H1SiCqgJSg+54XqURKp5aCMbrXrhLjRN9TjuwMjiYstZ0MzDrHqkGZ5dFTKd+zg== stubs@^3.0.0: @@ -3813,7 +3927,7 @@ type@^2.7.2: resolved "https://registry.npmjs.org/type/-/type-2.7.3.tgz" integrity sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ== -typescript@5.6.2: +"typescript@>= 2.7", typescript@>=2.7, "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta", typescript@>=5, typescript@5.6.2: version "5.6.2" resolved "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz" integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw== @@ -3830,7 +3944,7 @@ uglify-js@^3.19.3, uglify-js@^3.7.7: underscore@~1.13.2: version "1.13.8" - resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.13.8.tgz#a93a21186c049dbf0e847496dba72b7bd8c1e92b" + resolved "https://registry.npmjs.org/underscore/-/underscore-1.13.8.tgz" integrity sha512-DXtD3ZtEQzc7M8m4cXotyHR+FAS18C64asBYY5vqZexfYryNNnDc02W4hKg3rdQuqOYas1jkseX0+nZXjTXnvQ== undici-types@~6.21.0: @@ -3868,7 +3982,12 @@ uuid@^8.0.0: resolved "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz" integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== -uuid@^9.0.0, uuid@^9.0.1: +uuid@^9.0.0: + version "9.0.1" + resolved "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz" + integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== + +uuid@^9.0.1: version "9.0.1" resolved "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz" integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==